-->
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.  [ 7 posts ] 
Author Message
 Post subject: cascade-"all-delete-orphan" and dereferencing coll
PostPosted: Thu Nov 06, 2003 10:57 am 
Newbie

Joined: Tue Oct 14, 2003 3:05 pm
Posts: 4
I posted this before in a response to another post, but didn't get any replies, so I'm posting it again as a new post

According to Gavin,

gavin wrote:
You can't change a collection reference when the collection is mapped with cascade="all-delete-orphan".


Just make sure your getter returns the same collection instance and this exception will not occur.


That is a little easier said than done.

It is our practice to always make a copy of a collection passed in from a setter or out through a getter. I don't have TOO much of a problem doing this for the setter, since our setters for collections are private (only exist for the persistence implementation). But I have a hard time passing the same instance out of a getter that we are refering to in our class. Someone could modify the contents, I have to make sure the collection is thread safe, etc... I am curious to know why I can't change the reference, if I'm just copying the data. I can't think of a good reason why hibernate would need to refer to the same instance, but I'm sure you have one. Could someone suggest a workaround (i.e. create an immutable implementation of List and pass that to Hibernate; how would hibernate create an instance of that collection on retrieve.). Otherwise, I suppose we'll have to explictly delete orphaned objects. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I quote Gavin (You can recognize the style ;-))

Quote:
how the hell is Hibernate supposed to know what the orphans are?
(No, querying the db is NOT a solutions, since new children may have been added in the meantime.)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do NOT do this ever. Hibernate needs the original collection instance - it carries extra state that Hibernate needs.

If you absolutely insist on this shitty Joshua Block defensive coding style (which is only useful for people who don't write unit tests), then either

* give Hibernate its own accessors
* use access="direct" in Hibernate 2.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. sorry for gratuitous joshua block diss it was quite unnecessary ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
p.s.s. second apology, its actually called access="field"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:47 am 
Newbie

Joined: Tue Oct 14, 2003 3:05 pm
Posts: 4
Gavin,

Are you saying that we could have problems if we change the collection reference even if we are not using all-delete-orphan?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 11:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes. this is in the FAQ.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.