What is the best way of implementing a roundtrip for receiving XML files and eventually persisting the data into a database using Java. Currently I have:
1. An XML Schema & XML data files send to me
- the XSD is fairly complex and belongs to an external party, so I can not change it
2. Created the Java classes
- JAXB generates over 150 classes, unfortunately the schema can change
- I have used Maven POM to automate the process
3. Unmarshall the XML data files into Java objects (with JAXB annotation)
- the data would be displayed to the user to be manipulated
4. Persist the Java objects into a RDBMS (Oracle / MySQL)
- it seems JDO is the most suitable solution
5. Exporting the data
- The data can be exported again as XML or Excel (for example)
I can not find a suitable way to add JDO metadata or annotations to the Java source code (generated during the JAXB process) to ensure I can persist the Java classes. I am working with the following technologies:
- Java, Maven, JAXB, JDO & JDBC
I think DataNucleus would be most suited as I might have to change datastores (RDBMS / XML / Excel) often between environments with different export destinations. The only other two technologies I might need to consider is:
- Spring and XDoclet
Advice or a pointer to a tutorial would be appreciated
What is the best way of implementing a roundtrip for receiving XML files and eventually persisting the data into a database using Java.
For this I would use a combination of JAXB and JAXB. Note: I lead EclipseLink JAXB (MOXy), EclipseLink also provides an excellent JPA implementation.
Currently I have:
1 - An XML Schema & XML data files send to me
- the XSD is fairly complex and belongs to an external party, so I can not change it
Option #1 - Start from XML Schema
Option #2 - Start from Java Classes
2 - Created the Java classes
- JAXB generates over 150 classes, unfortunately the schema can change
- I have used Maven POM to automate the process
If the XML schema changes you can always regenerate your model, or annotate your model as necessary to handle the modifications to the XML schema.
You may find the HyperJAXB project useful, as I believe it will generate JPA annotations right onto a JAXB model.
3 - Unmarshall the XML data files into Java objects (with JAXB annotation)
- the data would be displayed to the user to be manipulated
This is just normal JAXB usage. For an example see:
4 - Persist the Java objects into a RDBMS (Oracle / MySQL)
- it seems JDO is the most suitable solution
JPA is another alternative.
5 - Exporting the data
- The data can be exported again as XML or Excel (for example)
Again this is normal JAXB usage to get the XML output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With