简体   繁体   中英

Best way to map JAXB to a database table

I have an inbound xml which I am mapping to JAXB objects using the xjc tool (to build the pojos)

I am wondering what the best approach is to map these objects to various tables.

An Object / Xml can map to multiple tables which rules hibernate out i think. As a basic solution I believe i need someway to annotate the fields in the objects maybe (via tags in the xsd? i dont know) to database column names.

Has anyone encountered this before?

Thanks

I guess you need Hyperjaxb3 that provides relational persistence for JAXB objects.

@lexicore is the author about this project.

You can use an extension for xjc - hyperjaxb

  • hyperjaxb2 - Relational persistence for XML data, with JAXB and Hibernate.
  • hyperjaxb3 - Persistence layer for JAXB objects.

For this purpose, hyperjaxb3 will be preferable.

Here is link to some tutorial Generate JPA Java classes from XSD schema file using Maven

If you have complex objects, schema-less database will greatly simplify development and processing time.

From my experience: got millions of XMLs with 200-300 different attributes, nested in several levels.

Spent several days on creating Entities for JAXB + JPA persisting. Insert speed was around 50 objects a second, split to 20-40 tables.

MongoDB's speed about 1000 objects a second. And NO development effort. Just read xml, convert it to JSON with org.json for example, convert json to BSON and insert.

Profiling showed that two conversions took negligible time (couple of percent). Most time was taken by saving to database (20-40 times faster than Oracle RDBMS).

Please refer to the below links for HyperJaxb .

Click for pdf

Click for web docs

Hope the above links will be helpful to you.

It's unclear what accordance between database schema and XML schema is. When there are too few generalizations and coherence between them then it's worst case, you need to couple XML and database by hands for every JAXB entity.

If there're good enough coherence and understandable rules you can try to write own code generator to create code of entities with JAXB and JPA annotations.

Also, try to look to an engine that supports both JAXB and JPA annotations out-of-box: EclipseLink .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM