-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: How to indicate a collection is uninitialized vs deleted
PostPosted: Thu Jun 17, 2010 10:51 am 
Newbie

Joined: Mon Jan 25, 2010 8:30 am
Posts: 7
I have a REST service that uses Hibernate to persist/retrieve its data. On the front end the service produces and consumes JSON.

During a record update the service receives the updated JSON record, unmarshalls that in to a new bean instance, and then calls EntityManager#merge(Object). At this point I get the error "A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity...". I understand this is because the bean instance is returning null for the particular collection in question.

Is there a way to inform Hibernate that the collection hasn't be removed, it just hasn't been initialized?


Top
 Profile  
 
 Post subject: Re: How to indicate a collection is uninitialized vs deleted
PostPosted: Fri Jun 18, 2010 5:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you shouldn't use "merge" on an object which might not exist on the database; Check first by loading it by primary key.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: How to indicate a collection is uninitialized vs deleted
PostPosted: Fri Jun 18, 2010 7:51 am 
Newbie

Joined: Mon Jan 25, 2010 8:30 am
Posts: 7
yes, you're right, I should have been checking to make sure it was still in the DB first. However, even after adding that I still get the same error. So, per my original post, is there any way to indicate that these mapped relationships aren't gone in my bean, they just aren't initialized?


Top
 Profile  
 
 Post subject: Re: How to indicate a collection is uninitialized vs deleted
PostPosted: Fri Jun 18, 2010 9:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
did you try cascading the merge?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: How to indicate a collection is uninitialized vs deleted
PostPosted: Fri Jun 18, 2010 10:32 am 
Newbie

Joined: Mon Jan 25, 2010 8:30 am
Posts: 7
Yes, the relationship is set to cascade all operations (i.e. CascadeType.ALL).


Top
 Profile  
 
 Post subject: Re: How to indicate a collection is uninitialized vs deleted
PostPosted: Mon Jun 28, 2010 7:41 am 
Newbie

Joined: Mon Jan 25, 2010 8:30 am
Posts: 7
Any other help on this topic?

In case my initial explanation wasn't clear here is a more concrete example.

I have two entities:

[code]
public class Person {

@ManyToOne(optional = false);
Organization org;

// various other properties, getters, and setters
}
[/code]

and

[code]
public class Organization {

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true);
@Sort(type = SortType.COMPARATOR, comparator = ModelComparator.class);
SortedSet<Person> members;

// various other properties, getters, and setters
}
[/code]

My web service looks up an instance of Organization and serializes it out to the client WITHOUT initializing the members collection (if the client wants all or part of the member list it must make a separate call). Client does its modifications and sends an update message to the server, the message body is deserialized in to a new'ed Organization object. The members collection is null just as it was when it was serialized out. I then called EntityManager#merge with the Organization and get the aforementioned error: "A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity...".

In general the system seems to be behaving as if either merge does not ever work with detached objects (which is not what I expected from reading the spec) or as if the entire object graph must be initialized before the object is detached (also not what I expected).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.