-->
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.  [ 3 posts ] 
Author Message
 Post subject: Need to allow shared references to collections
PostPosted: Fri Apr 21, 2006 8:29 am 
Newbie

Joined: Fri Sep 16, 2005 4:43 am
Posts: 2
Is there a way to allow shared references to collections? Is there a reason for not allowing this, even when the collection is read-only(should nver be updated to database)?
Or do I have to remove the mappings and instead load these collections from hql? (Means a lot of code we'll have to change..)

Anybody out there with a solution to this problem? Been thinking about tweaking the hibernate code.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 9:15 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That depends what you mean be "shared references". There is a hibernate excpetion that mentions "shared references to a collection", and I'm guessing that that's what you're thinking of. However, it's a poorly-described exception, as the references are not shared, and that's the point.

It is fine to pass a persistent collection around to lots of places, sharing the use of a single instance. If you're doing that, continue doing it and all will be well. The problem occurs when you don't do that: when you have two distinct and separate references to a single collection. The most common way of getting into that situation is when you create a transient collection in transient object, then persist it and load it. The loaded collection is now the "real" collection, and the original collection should be immediately discarded. If you re-save that original object or collection you'll get the "shared reference" exception.

There is no way to allow two different java collections refer to a single persistent collection. There is no way for hibernate to synchronize something like that: what if you remove one item from one collection, and add a different item to the other collection, then save both.. what happens? If you want two references to the same collection, that's fine, the only problem is when you have two different java collections referring to the same set of DB rows.

If the collection is truly read-only, then either map it as mutable="false", or at least detach it from the session. The easiest way to detach the collection is to Hibernate.initialize it, then session.evict or session.clear.


Top
 Profile  
 
 Post subject: Re: Need to allow shared references to collections
PostPosted: Tue Dec 14, 2010 4:26 am 
Newbie

Joined: Tue Dec 14, 2010 4:21 am
Posts: 3
I have getting "Found shared references to a collection" Same error is their any problem if i have written " hibernate.cache usage="read-only" include="all"" for that particular bean.
And this error got first time ever. So What will be problem .And What is solution to solve this?


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