See
https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html#Parent_pointers
jeff wrote:
> say i have classes Book and Page. a Book has many pages, and a Page has one Book. so in JPA terms there's a one-to-many bidirectional relationship ... there's a Book.getPages() method, and a Page.getBook() method.
>
> so, the XML might look like ...
>
> <book name="...">
> <page number="1">...</page>
> <page number="2">...</page>
> ...
> </book>
>
> what i want is a way to cause Page.book to be populated when the XML document is unmarshaled. unless i add an XML element "book" to the Page, JAXB won't know or care anything about the Page.book field. obviously, that would be strange,
>
> <book name="x">
> <page number="1" book="x">...</page>
>
> in the XML schema, the ownership of a Page by a Book is implied by the nesting, but in JPA this must be done explicitly by setting Page's book field.
>
> if Page.book is not populated, then the bidirectional relationship is not correctly setup, and a JPA persist will fail.
>
> the goal is to be able to unmarshal the document, persist it with JPA, fetch it using JPA, then marshal it again.
>
>
> any ideas?
> thanks!
>
>
>
> ---------------------------------
> Don't be flakey. Get Yahoo! Mail for Mobile and
> always stay connected to friends.
>
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com