|
|
|
|
Infinite XML Loop
Posted:
Aug 10, 2007 3:24 AM
|
|
|
|
|
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: kennethHYPERLINK "mailto:kenneth@rabiddog.co.za"@rabiddog.co.za Web: HYPERLINK "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 [att1.html]
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Aug 10, 2007 4:31 AM
in response to: Kenneth Clark
|
|
|
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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> > *Web: *_http://www.rabiddog.co.za <http://_ > > > 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@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
RE: Infinite XML Loop
Posted:
Aug 10, 2007 8:52 AM
in response to: Sahoo
|
|
|
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@rabiddog.co.za Web: http://www.rabiddog.co.za -----Original Message----- From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of Sahoo Sent: Friday, August 10, 2007 13:32 To: users@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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> > *Web: *_http://www.rabiddog.co.za <http://_ > > > 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@glassfish.dev.java.net For additional commands, e-mail: users-help@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@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Aug 10, 2007 11:23 AM
in response to: Kenneth Clark
|
|
|
Are you sure that the exception comes from the query? It seems like an xml processing error.
thanks, -marina
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@rabiddog.co.za > Web: http://www.rabiddog.co.za > -----Original Message----- > From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of > Sahoo > Sent: Friday, August 10, 2007 13:32 > To: users@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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> >>*Web: *_http://www.rabiddog.co.za <http://_ >> >> >>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@glassfish.dev.java.net > For additional commands, e-mail: users-help@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@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
RE: Infinite XML Loop
Posted:
Aug 12, 2007 10:14 PM
in response to: Marina Vatkina
|
|
|
Hi
I can think of any other reason as all I am doing is executing a query.
The service is defined as
@WebMethod public List<AccountType> queryAccountTypeFindAll() { return em.createNamedQuery("AccountType.findAll").getResultList(); }
The AccountType object has a reference to an a Collection of type EntityAccountInformation and each instance of EntityAccountInformation has a single reference to AccountType.
I don't know what I have done wrong here. Never seen this before to be honest (this error that is) will dig deeper and see what I come across.
Thanks for the input thus far
Kenneth Clark Solution Architect / Lead Developer Rabid Dog Labs
Tel: +27 11 475 7409 Mobile: +27 82 500 5090 Email: kenneth@rabiddog.co.za Web: http://www.rabiddog.co.za -----Original Message----- From: Marina.Vatkina@Sun.COM [mailto:Marina.Vatkina@Sun.COM] Sent: Friday, August 10, 2007 20:23 To: users@glassfish.dev.java.net Subject: Re: Infinite XML Loop
Are you sure that the exception comes from the query? It seems like an xml processing error.
thanks, -marina
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@rabiddog.co.za > Web: http://www.rabiddog.co.za > -----Original Message----- > From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of > Sahoo > Sent: Friday, August 10, 2007 13:32 > To: users@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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> >>*Web: *_http://www.rabiddog.co.za <http://_ >> >> >>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@glassfish.dev.java.net > For additional commands, e-mail: users-help@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@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@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
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Aug 10, 2007 11:44 AM
in response to: Kenneth Clark
|
|
|
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@rabiddog.co.za > Web: http://www.rabiddog.co.za > -----Original Message----- > From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of > Sahoo > Sent: Friday, August 10, 2007 13:32 > To: users@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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> >> *Web: *_http://www.rabiddog.co.za <http://_ >> >> >> 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@glassfish.dev.java.net > For additional commands, e-mail: users-help@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@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
RE: Infinite XML Loop
Posted:
Aug 12, 2007 10:28 PM
in response to: Sahoo
|
|
|
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@rabiddog.co.za Web: http://www.rabiddog.co.za
-----Original Message----- From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of Sahoo Sent: Friday, August 10, 2007 20:44 To: users@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@rabiddog.co.za > Web: http://www.rabiddog.co.za > -----Original Message----- > From: Sanjeeb.Sahoo@Sun.COM [mailto:Sanjeeb.Sahoo@Sun.COM] On Behalf Of > Sahoo > Sent: Friday, August 10, 2007 13:32 > To: users@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@rabiddog.co.za <mailto:kenneth@rabiddog.co.za> >> *Web: *_http://www.rabiddog.co.za <http://_ >> >> >> 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@glassfish.dev.java.net > For additional commands, e-mail: users-help@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@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@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
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Oct 16, 2007 4:18 PM
in response to: Kenneth Clark
|
|
|
I am also getting the same error - A cycle is detected in the object graph. This will cause infinitely deep XML whenever there is a circular reference.
I followed Sahoo's advice by making object reference to null. Now I am getting an exception - Cannot update the record.
Looks like when i am making the object reference null it is synchronizing the inmemory object with database and hence it is updating the database and kicks out with exception - cannot update - value cannot be null.
How can i prevent it from updating the database or rather stop synchronizing the inmemory object with datasbe for this.
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Oct 16, 2007 8:25 PM
in response to: ad1900
|
|
|
I guess you are setting the object references null in a managed instance in a transactional method? Can you detach the instance before modifying it? In the mean while, let me think if if there is an alternative way to handle this.
Thanks, Sahoo
glassfish@javadesktop.org wrote: > I am also getting the same error - A cycle is detected in the object graph. This will cause infinitely deep XML whenever there is a circular reference. > > I followed Sahoo's advice by making object reference to null. Now I am getting an exception - Cannot update the record. > > Looks like when i am making the object reference null it is synchronizing the inmemory object with database and hence it is updating the database and kicks out with exception - cannot update - value cannot be null. > > How can i prevent it from updating the database or rather stop synchronizing the inmemory object with datasbe for this. > [Message sent by forum member 'ad1900' (ad1900)] > > http://forums.java.net/jive/thread.jspa?messageID=240546 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Oct 17, 2007 9:37 AM
in response to: ad1900
|
|
|
Sahoo
Here is my stateless Session Bean
@Stateless @WebService public class ValidAppStatusFacade implements ValidAppStatusFacadeLocal {
@PersistenceContext private EntityManager em; /** Creates a new instance of ValidAppStatusFacade */ public ValidAppStatusFacade() { }
public List findAll() { List list = (List)em.createQuery("select object(o) from ValidAppStatus as o").getResultList(); for(Iterator<ValidAppStatus> i = list.iterator(); i.hasNext(); ){ ValidAppStatus validApp = i.next(); for(Application application:validApp.getApplicationCollection()){ application.applicationStatus = null; //break cycle -- How do i detach applicationSttaus from application } } return list; } }
Sorry, how can i detach applicationStatus in the above method.
Thanks
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Oct 22, 2007 8:30 PM
in response to: ad1900
|
|
|
Since yours is a read-only method, you can easily work around this by problem by simply detaching the objects before returning from the function: *em.clear();* // detach all the entities, so updates won't go to database return list;
Thanks, Sahoo
glassfish@javadesktop.org wrote: > Sahoo > > Here is my stateless Session Bean > > > @Stateless > @WebService > public class ValidAppStatusFacade implements ValidAppStatusFacadeLocal { > > @PersistenceContext > private EntityManager em; > > /** Creates a new instance of ValidAppStatusFacade */ > public ValidAppStatusFacade() { > } > > > public List findAll() { > > List list = (List)em.createQuery("select object(o) from ValidAppStatus as o").getResultList(); > for(Iterator<ValidAppStatus> i = list.iterator(); i.hasNext(); ){ > ValidAppStatus validApp = i.next(); > for(Application application:validApp.getApplicationCollection()){ > application.applicationStatus = null; //break cycle -- How do i detach applicationSttaus from application > } > } > return list; > > } > } > > Sorry, how can i detach applicationStatus in the above method. > > Thanks > [Message sent by forum member 'ad1900' (ad1900)] > > http://forums.java.net/jive/thread.jspa?messageID=240705 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Infinite XML Loop
Posted:
Nov 22, 2009 9:53 AM
in response to: Sahoo
|
|
|
Please don't do what's been suggested above - traversing your references programmatically and trying to set one side of these parent-child relationships to null is going to be quite error-prone and a problem for code maintenance.
The way to handle this is to place the @XmlTransient annotation on one side of the relationship so that JAXB doesn't try to convert it to XML.
If you've got a class, say Category, with methods for getParentCategory() and getChildCategories(), you should put the @XmlTransient annotation on the getParentCategory() method - this way JAXB won't try to convert both the parent and the children to XML, which is what's causing this infinite loop.
If, on the client-side of the Web Service, you require that the getParentCategory() method properly returns the parent category, you'll have to iterate over the results and for every child category call setParentCategory().
Message was edited by: ryan_kimber
|
|
|
|
|