users@glassfish.java.net

Re: A cycle is detected in the object graph

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 05 Nov 2007 14:56:51 -0800

You need to disconnect objects after/when they are detached. Either use a non-tx
query, or close/clear em before nullifying the references.

Regards,
-marina

Kenneth Clark wrote:
> I am faced with quite a challenge here.
>
>
>
> I have the objects ClientProfile and Subscription:
>
>
>
> The ClientProfile contains a collection of Subscriptions:
>
> ______________________________________________________________________
>
> public class ClientProfile implements Serializable {
>
>
>
> @OneToMany(mappedBy = "clientProfile", cascade={CascadeType.MERGE,
> CascadeType.PERSIST})
>
> private List<Subscription> subscriptionCollection;
>
>
>
> public ClientProfile() {
>
> }
>
>
>
> public List<Subscription> getSubscriptionCollection() {
>
> return subscriptionCollection;
>
> }
>
>
>
> public void setSubscriptionCollection(List<Subscription>
> subscriptionCollection) {
>
> this.subscriptionCollection = subscriptionCollection;
>
> }
>
> }
>
> ______________________________________________________________________
>
>
>
> public class Subscription implements Serializable {
>
> @ManyToOne
>
> @JoinColumn(name = "client_profile_id", referencedColumnName = "id")
>
> private ClientProfile clientProfile;
>
>
>
> public Subscription() {
>
> }
>
>
>
> public ClientProfile getClientProfile() {
>
> return clientProfile;
>
> }
>
>
>
> public void setClientProfile(ClientProfile clientProfile) {
>
> this.clientProfile = clientProfile;
>
> }
>
> }
>
>
>
> Now if I want to push this down via a webservice, everytime I try I get
> “A cycle is detected in the object graph”. Now I understand why this is
> happening but then I try and set the client profile inside the
> subscription collection to Null (to break the graph) I am getting a
> constraint failure because of the foreign key. It is as if when I set
> the client profile value inside subscription it wants to perform an update.
>
>
>
> Does anyone know how to get round this? How do I send this to my client
> app with the clientProfile and it’s subscription list in tact?
>
> ________________
>
> Thanks and regards
>
>
>
> *Kenneth Clark*
>
> Solutions Engineer
>
>
>
> ShadowLogo.png
>
> *Tel:** *27 11 679 3075
>
> *Mobile:** *27 (0) 84 583 1348**
>
> *Email:** *_kenneth.clark_at_skyetech.co.za
> <mailto:kenneth.clark_at_skyetech.co.za>_
>
> *Website:** *http://www.skyetech.co.za**
>
>
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.15.22/1111 - Release Date:
> 2007/11/05 04:36
>