users@glassfish.java.net

RE: Infinite XML Loop

From: Kenneth Clark <kenneth_at_rabiddog.co.za>
Date: Mon, 13 Aug 2007 07:28:32 +0200

That seems to have resolved it. 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
Web: http://www.rabiddog.co.za

-----Original Message-----
From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM] On Behalf Of
Sahoo
Sent: Friday, August 10, 2007 20:44
To: users_at_glassfish.dev.java.net
Subject: Re: Infinite XML Loop

I am assuming you are getting the error from JAXB marshaling layer.

Before you return the object graph to the client, break the cycle by
setting null values in a particular direction. e.g.,

Employee {
  String id;
  @ManyToOne
  Dept dept;
}

class Dept {
  String id;
  @OneToMany(mappedBy="dept")
  Collection<Employee> employees;
}

@WebService
class FooEJB {
   Dept getDept(String id) {
       Dept d = em.find(id);
       for(Employee e : d.employees) {
           e.dept = null; // break the cycle
       }
       return d;
   }
}

If you search for JAXB and that error, you can find some document
written by Kohsuke that talks about how to handle it in the JAXB layer
as well.

Thanks,
Sahoo

Kenneth Clark wrote:
> I am not understanding what you mean unfortunately.
>
> If I remove references to objects inside objects I effectively break my
> model. How would I go about setting references to null if I am doing a
> straight "Select o From AccountType o"?
>
> Unless there is a better mechanism to select all the objects I am at a
loss
> here.
>
> 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
> Web: http://www.rabiddog.co.za
> -----Original Message-----
> From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM] On Behalf Of
> Sahoo
> Sent: Friday, August 10, 2007 13:32
> To: users_at_glassfish.dev.java.net
> Subject: Re: Infinite XML Loop
>
> 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
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.476 / Virus Database: 269.11.11/944 - Release Date:
2007/08/09
> 14:44
>
>
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 2007/08/12
11:03
 

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 2007/08/12
11:03