public void testDom4jRetreival() { Session session = openSession(); Transaction txn = session.beginTransaction(); org.hibernate.Session dom4j = session.getSession(EntityMode.DOM4J); prepareTestData(session); Object rtn = dom4j.get(Stock.class.getName(), stockId); Element element = (Element) rtn; assertEquals("Something wrong!", stockId, Long.valueOf(element.attributeValue("id"))); System.out.println("**** XML: ****************************************************"); prettyPrint(element); System.out.println("**************************************************************"); Element currVal = element.element("currentValuation"); System.out.println("**** XML: ****************************************************"); prettyPrint(currVal); System.out.println("**************************************************************"); txn.rollback(); session.close(); }
public void testDom4jSave() { Session pojos = openSession(); Transaction txn = pojos.beginTransaction(); prepareTestData(pojos); org.hibernate.Session dom4j = pojos.getSession(EntityMode.DOM4J); Element stock = DocumentFactory.getInstance().createElement("stock"); stock.addElement("tradeSymbol").setText("IBM"); Element val = stock.addElement("currentValuation").addElement("valuation"); val.appendContent(stock); val.addElement("valuationDate").setText(new java.util.Date().toString()); val.addElement("value").setText("121.00"); dom4j.save(Stock.class.getName(), stock); dom4j.flush(); txn.rollback(); pojos.close(); assertTrue(!pojos.isOpen()); assertTrue(!dom4j.isOpen()); prettyPrint(stock); }
public void testDom4jHQL() { Session session = openSession(); Transaction txn = session.beginTransaction(); org.hibernate.Session dom4j = session.getSession(EntityMode.DOM4J); prepareTestData(session); List result = dom4j.createQuery("from Stock").list(); assertEquals("Incorrect result size", 1, result.size()); Element element = (Element) result.get(0); assertEquals("Something wrong!", stockId, Long.valueOf(element.attributeValue("id"))); System.out.println("**** XML: ****************************************************"); prettyPrint(element); System.out.println("**************************************************************"); txn.rollback(); session.close(); }