I would like to know if there is a java XML persistence api out there?
In fact,I want an api like hibernate which can persist/retrieve plain old java objects to/from an xml store which conforms to a given schema. This schema defines foreign key,but objects use aggregation like in hibernate mapping.
Let me explain you the problem behind this problem.I've used hibernate to persist some objects to a relational database.Now I want to persist/retrieve these objects to/from a xml store which is an instance of a schema. This xml schema is in fact an xml version of the database schema. Of course, I don't want to modify existing pojo classes. I just want another persistence(an xml one) implementation.
I've seen JAXB,but it constraints me to use classes that it has generated,isn't it(please correct me if I am wrong)? Moreover,it doesn't seem to persist objects to aggregation
Do you know the experimentale part of hibernate :
Maybe it can help you ?
Thanks for your answer,
I've explored documentation about Hibernate and XML.It seems that I must open a database session before open a DOM4J session. Moreover,It is not possible to retrieve objects from an xml storage.
Here is an example of what I want to achieve:
/**XMLSession is an imaginary class(or interface) which is used to manipulate an xml doc.
The factory is configured in properties file where we specify the xml file to handle.Just like we sp
ecify database parameters in hibernate.properties
//Store an object to an XML file
XMLSession xmlSess = factory.getSession();
Employee e = new Employee();
e.setAge(25); //too much or too low?? :-)
Employee e1 = new Employee();
e1.setAge(35); //too much or too low?? :-)
Company c = new Company ();
xmlSess.store(c);//persist company object and his employees
//Retrieve an object and update it
Employee who = xmlSess.load(Employee.class, 1);//1=id
xmlSess.close();//certainly release i/o resource??
So,I just want to replace database persistence by an xml file and create a mapping file between classes and the xml schema.
Is it possible with Hibernate? if not,is there another solution out there?
Check CASTOR it allows you to use non JAXB sensitive POJOs through external mapping files. Can read and write too to XML files.
Not ment for this purpose, but if it solves your problem :|