• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Combine JAXB + JPA?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic