3

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

wacko
  • 31
  • 2

2 Answers2

1

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

  • If you want to start from XML schema you can use JAXB's external binding file to customize the class generation as needed without modifying third party 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.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
0

Storing, in database, instances of Java objects generated by JAXB from an evolving XML schema doesn't make much sense, IMHO. The goal of a relational database is to store data, in a well-defined relational structure, in order to be able to query it easily.

If all you want is to be able to get back the XML document you received some time before, as is, just store it as a clob in some table, or in the file system.

If storing the data in database in a structured way is really needed, then design your database schema first, then design the JDO classes needed to map this database schema, and implement the business logic needed to transform your JAXB objects into JDO objects in order to store them in database.

But I would think more about what functionality you want to implement before thinking about the technologies you want to use.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Could not agree more, but I do not have the option of saving a XML clob. The XML Schema (XSD) might change, hopefully once in 2 years. The JAXB generated classes (from the XSD) forms the basic data relationship/structure, thus the need to automate the ORM process (possibly using JDO) without manually annotating 150+ classes adding `@Persistent` to each, or creating `persistence.xml` (or similar) metadata. I am hoping DataNucleus Enhance or Spring Injection can help me out. – wacko Mar 01 '11 at 12:55