users@jaxb.java.net

Re: jaxb 2.0, schemagen

From: Levi Purvis <javanet_at_purvis.ws>
Date: Fri, 23 Feb 2007 21:30:28 -0500

We're using JPA & JAXB2 on the same set of classes. We're coding the
Java classes by hand and generating the schema, rather than coding the
schema by hand and generating the Java classes. i.e.

1. define JPA entity classes
2. add a few JAXB2 annotations
3. done

You actually don't even need many of the JAXB2 annotations in your
Java classes, if you make your Java names match what you want in your
XML.

On 2/23/07, jeff wrote:
> hello,
>
> i am hoping someone here can explain the best way to handle this situation
> ...
>
> we want to have a set of classes that are both JPA persistable and XML
> marshal/unmarshalable. so, for example, i can create an object from an XML
> document, persist that object using JPA. and vice versa, load an object
> using JPA, and then export it as XML.
>
> so, for example, is this the best approach?
>
> 1. define JPA entity classes
> 2. use schemagen to generate XSD from those classes
> 3. use XJC to compile the XSD
> 4. have some custom code that converts JAXB-generated classes into JPA
> entity classes, and vice versa
>
> i don't like step 4 obviously. so another option ...
>
> 1. define XSD
> 2. use XJC to compile the XSD
> 3. modify the generated sources manually to add JPA annotations
>
> this seems wrong though, because for example if in jaxb 2.next the
> annotations change, i imagine i'd have to re-compile the XSD and add back in
> the JPA annotations manually. this sort of violates a cardinal rule: thow
> shalt never commit generated source files.
>
> thanks much.