users@glassfish.java.net

Re: Infinite XML Loop

From: Sahoo <Sahoo_at_Sun.COM>
Date: Fri, 10 Aug 2007 17:01:30 +0530

That exception typically comes from JAXB marshaling code when it detects
a cycle in the object graph. Are you returning the object from a web
service? Your in-memory object probably has the bidirectional references
set up, this can happen if you traverse the relationships in your code.
So, instead of relying on fetch type, you should explicitly cut the
cycles in the graph by setting some references null.

Thanks,
Sahoo

Kenneth Clark wrote:
>
> Hi guys
>
> I have a bi-directional relationship and everytime I try and fetchAll
> I am getting the error
>
> “com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML:”
>
> The mapping in the AccountType class is:
>
> @OneToMany(mappedBy = "accountType", fetch=FetchType.LAZY)
>
> private Collection<EntityAccountInformation>
> entityAccountInformationCollection;
>
> And the mapping in the EntityAccountInformation is
>
> @ManyToOne
>
> @JoinColumn(name = "account_type_id", referencedColumnName = "id")
>
> private AccountType accountType;
>
> Do I have to remove the bidirectional relationship to resolve this?
> Why is it ignoring the FetchType?
>
> I enabled the toplink.weaving property (read that it might stop this)
>
> <property name="toplink.weaving" value="true"/>
>
> But nothing seems to be helping.
>
> Any feed back would be great
>
> Thanks
>
> Kenneth Clark
> *Solution Architect / Lead Developer**
> **Rabid Dog Labs*
>
>
> *Tel:* +27 11 475 7409
>
> *Mobile**:* +27 82 500 5090
> *Email:* kenneth_at_rabiddog.co.za <mailto:kenneth_at_rabiddog.co.za>
> *Web: *_http://www.rabiddog.co.za <http://www.rabiddog.co.za/>_
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.476 / Virus Database: 269.11.11/944 - Release Date:
> 2007/08/09 14:44
>