-->
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: NotUniqueObjectException
PostPosted: Tue Jun 13, 2006 12:57 pm 
Newbie

Joined: Tue Jun 13, 2006 11:30 am
Posts: 2
Hi Guys,

I have a question about getting a NotUniqueObjectException.

I have an object with a collection of objects that point to other immutable objects in a Many to Many relationship. The objects at the end of the Many to Many relation ship are basically "Lookup" objects. I get this exception when one of these objects turns up more then once in my object tree (As a lookup value should) and I Lock a detached object back onto a new session.
The exception is pretty clear:
NonUniqueObjectException:
'a different object with the same identifier value was already associated with the session'


I have debugged this alot and have found that Reassociate is getting called for all objects in my object tree.

There is an IdentityMap dictionary called entityEntries in the NHibernate session obect that the Lock method uses before calling Reassociate to check if the object has already been added to the session and get session information about the object. When my object comes along for the second time this dictionary can't find it in the map (I can see it in there!!) and returns Null. This causes the Reassociate to run on an object that's already in the entitiesByKey dictionary and therefore the exception as it's representing the same object.

I think that my lookup objects are different instances, but with identical data.
What I would like to know, is what is the Identity Map object using to compare my objects that means it doesn't find this object when it's already in there. Is it some hashing magic that can see my objects are different ??

Hibernate version: 1.0.1.0



Full stack trace of any exception that occurs:
NHibernate.DLL!NHibernate.Impl.SessionImpl.CheckUniqueness(NHibernate.Engine.Key key = {33}, object obj = {3118 : FOOD: Bakery Products}) Line 1903
NHibernate.DLL!NHibernate.Impl.SessionImpl.Reassociate(object obj = {3118 : FOOD: Bakery Products}, object id = 33, NHibernate.Persister.IClassPersister persister = {NHibernate(HSI.Business.Impl.IndustryCode)}) Line 1912 + 0xd bytes
NHibernate.DLL!NHibernate.Impl.SessionImpl.Lock(object obj = {3118 : FOOD: Bakery Products}, NHibernate.LockMode lockMode = {None}) Line 1953 + 0x12 bytes
NHibernate.DLL!NHibernate.Engine.Cascades.CascadingAction.ActionLockClass.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {3118 : FOOD: Bakery Products}, object anything = {None}) Line 125 + 0x2d bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {3118 : FOOD: Bakery Products}, NHibernate.Type.IType type = {NHibernate.Type.ManyToOneType}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 559 + 0x11 bytes
NHibernate.DLL!NHibernate.Engine.Cascades.CascadeCollection(NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllClass}, NHibernate.Type.PersistentCollectionType collectionType = {NHibernate.Type.SetType for HSI.Business.Impl.Experience.IndustryCodes}, NHibernate.Type.IType elemType = {NHibernate.Type.ManyToOneType}, object child = {Iesi.Collections.ListSet}, NHibernate.Engine.CascadePoint cascadeVia = CascadeOnUpdate, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object anything = {None}) Line 677 + 0x1a bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {Iesi.Collections.ListSet}, NHibernate.Type.IType type = {NHibernate.Type.SetType for HSI.Business.Impl.Experience.IndustryCodes}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 579 + 0x1e bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, NHibernate.Persister.IClassPersister persister = {NHibernate(HSI.Business.Impl.Experience)}, object parent = {Senior Manager, Sales and Customer Service Systems}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 638 + 0x3e bytes
NHibernate.DLL!NHibernate.Impl.SessionImpl.Lock(object obj = {Senior Manager, Sales and Customer Service Systems}, NHibernate.LockMode lockMode = {None}) Line 1958 + 0x19 bytes
NHibernate.DLL!NHibernate.Engine.Cascades.CascadingAction.ActionLockClass.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {Senior Manager, Sales and Customer Service Systems}, object anything = {None}) Line 125 + 0x2d bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {Senior Manager, Sales and Customer Service Systems}, NHibernate.Type.IType type = {NHibernate.Type.ManyToOneType}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllDeleteOrphanClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 559 + 0x11 bytes
NHibernate.DLL!NHibernate.Engine.Cascades.CascadeCollection(NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllDeleteOrphanClass}, NHibernate.Type.PersistentCollectionType collectionType = {NHibernate.Type.SetType for HSI.Business.Impl.Candidate.Experiences}, NHibernate.Type.IType elemType = {NHibernate.Type.ManyToOneType}, object child = {Iesi.Collections.ListSet}, NHibernate.Engine.CascadePoint cascadeVia = CascadeOnUpdate, NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object anything = {None}) Line 677 + 0x1a bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, object child = {Iesi.Collections.ListSet}, NHibernate.Type.IType type = {NHibernate.Type.SetType for HSI.Business.Impl.Candidate.Experiences}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.Cascades.CascadeStyle style = {NHibernate.Engine.Cascades.CascadeStyle.StyleAllDeleteOrphanClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 579 + 0x1e bytes
NHibernate.DLL!NHibernate.Engine.Cascades.Cascade(NHibernate.Engine.ISessionImplementor session = {NHibernate.Impl.SessionImpl}, NHibernate.Persister.IClassPersister persister = {NHibernate(HSI.Business.Impl.Candidate)}, object parent = {ADAMO, Steven J (5622)}, NHibernate.Engine.Cascades.CascadingAction action = {NHibernate.Engine.Cascades.CascadingAction.ActionLockClass}, NHibernate.Engine.CascadePoint cascadeTo = CascadeOnUpdate, object anything = {None}) Line 638 + 0x3e bytes
NHibernate.DLL!NHibernate.Impl.SessionImpl.Lock(object obj = {ADAMO, Steven J (5622)}, NHibernate.LockMode lockMode = {None}) Line 1958 + 0x19 bytes
HSI.Business.DLL!HSI.Business.Persister.LazyCollectionLoader.LoadCollection(Object anObject = {HSI.Business.Impl.Candidate}, String collectionName = "_addresses") Line 22 + 0x1d bytes
HSI.Business.DLL!HSI.Business.Facade.Loader.Load(Object anObject = {HSI.Business.Impl.Candidate}, String collectionName = "_addresses") Line 24 + 0x13 bytes
HSI.Business.DLL!HSI.Business.Impl.Candidate.get_Addresses() Line 374 + 0xd bytes
App_Web_t0gkrlzw.dll!Search.btAddresses_Click(Object sender = {Text = "|address|"}, System.EventArgs e = {System.EventArgs}) Line 548 + 0x1a bytes

[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 1:02 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
probably a dumb question but have you implemented Equals() and GetHashCode() on your "Lookup" object?

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 1:55 pm 
Newbie

Joined: Tue Jun 13, 2006 11:30 am
Posts: 2
I didn't have those implemented for my Business objects when this exception started happening, but I put in a very simple GetHashCode and Equals. These were returning suitable values for these functions that worked everywhere else.
They didn't affect the entityEntries Object missing my object though.

I have noticed that entityEntries is an NHibernate SequencedHashMap and "Seems" to use an external Hashcodeprovider.dll to work out it's own hashes. This is the one that I think is doing something sneaky.

Does anyone know what this SequencedHashMap is using to compare objects??


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.