You don't have to use an explicit object factory if you're coding the
Java class by hand. You can just create them with normal constructors
(you need a default constructor for each class for JAXB2, though it
doesn't have to be public).
If you download the JAXB 2.1 distribution, take a look in the samples/
folder and in the various j2s-* folders (short for java2schema I
think). There's some example code in there to get you started with
that approach.
On 2/26/07, jeff wrote:
> hi levi, thanks for your response ...
>
> if you don't use xjc, where does your object factor class come from?
>
> i am new to jaxb 2.x, so please excuse me if i am missing something
> fundamental.
>
>
> Levi Purvis wrote:
> 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.