christian wrote:
XML databinding is now built-in, check the documentation.
I found the new XML code, but I'm not quite sure it does what I'm looking for. In my app, I won't know beforehand that a given set is going to end up in XML. It's just a data set that at some point the user may decide to export to xml (or they may not).
So I want to get it back from Hibernate as a list of POJOs and then (maybe) export it as an XML document. The Hibernate XML support I've found so far seems to require me to tell hibernate at query time that I want to get XML data back. Am I wrong on this? Alternately is there a quick and easy way to translate a POJO set into and XML set?
Below is the code snipper I'm working on for reference.
Code:
Document d;
d = createDomDocument();
Session session = HibHelper.getSession();
Session dom4jSession = session.getSession(EntityMode.DOM4J);
HibHelper.beginTransaction();
List results = dom4jSession.createCriteria("core.User").list();
Element root = d.addElement( "root" );
for ( int i=0; i<results.size(); i++ ) {
Element u = (Element) results.get(i);
root.add(u);
}
HibHelper.commitTransaction();
try {
FileWriter w = new FileWriter(f);
d.write(w);
w.close();
} catch (IOException e) {
Log.error(e);
}