|
HyperJAXB - relational persistence for XML objects with JAXB and HibernateWhat is HyperJAXB?HyperJAXB is an add-on for Sun's reference implementation of JAXB (Java Architecture for XML Binding). It provides JAXB objects with relational persistence layer using Hibernate. What can I do with HyperJAXB?HyperJAXB eases usage of XML with relational databases. With HyperJAXB you can combine JAXB and Hibernate to implement one of the following target usage scenarios:
How it works?JAXB is basically a code generation engine. It accepts a schematic definition of you XML documents (usually in the form of an XML Schema) as input and generates source code of XML-enabled classes. HyperJAXB augments generated code by adding Hibernate XDoclet annotations. Added annotations effectively define Hibernate O/R mapping for the generated classes. Combination of JAXB RI, HyperJAXB and Hibernate toolset allows you automatically generate the following artifacts out of you XML Schema:
Please see the reference for more information. A code example?Unmarshalling and saving: // Unmarshall the document final MyObject myObject = (MyObject) unmarshaller.unmarshal(document); // Open the session, save object into the database final Session saveSession = sessionFactory.openSession(); // Save id for the later use final String id = saveSession.save(myObject); saveSession.flush(); // Close the session saveSession.close() Loading and marshalling: // Open the session, load the object final Session loadSession = sessionFactory.openSession(); final MyObject myLoadedObject = (MyObject) loadSession.load(MyObject.class, id); loadSession.close(); // Marshall loaded object into the document final Document loadedDocument = documentBuilder.newDocument(); marshaller.marshal(myLoadedObject, loadedDocument); Mapping generated by HyperJAXB ensures that document and loadedDocument are identical. Where can I find it?Check out this project on https://hyperjaxb.dev.java.net. |
||||||||