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...
Joined: Oct 01, 2007
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.
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.