Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combine JAXB + JPA?

 
Ryan Kumsher
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating REST services to insert users into a database using JERSEY, JAXB, and JPA. I am new to all 3 technologies...

Currently I am accepting a JAXB user object.
Converting to a JPA user object using a helper class I wrote
Then persisting the JPA user



Is there an easy way (automatic code generation hopefully) to combine the JAXB and JPA classes so I don't have to convert the JAXB user class into a JPA user class? This way I could just call em.persist(user) on the object passed in to the addUser method. It looks like EclipseLink Moxy might be of use here but couldn't find a good example...

Thanks
 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the same objects/class in both JAXB and JPA. You can include annotations for both JPA and JAXB to map the same class to both XML and a database.

EclipseLink supports both JPA and JAXB in a single product.

This depends on what data you are sending through XML and to the database though. If the data is very different, then you may wish to have different objects. If there are no major differences in the data, then since both JAXB and JPA allow configurable mappings, you should be able to use both.

See,
http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
 
Ryan Kumsher
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blaise,

Thanks a lot for the in depth posts. This was real helpful for me in learning some of the basics of JPA and JAXB. I'm looking forward to implementing this technique and getting rid of my ugly helper class I wrote to convert between the 2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic