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.  [ 4 posts ] 
Author Message
 Post subject: Missing: org.hibernate.NonUniqueObjectException
PostPosted: Wed Sep 17, 2008 6:04 am 
Newbie

Joined: Wed Sep 17, 2008 5:44 am
Posts: 3
Hi,
this could be difficult. I see some strange behaviour and right now I can only explain it with the fact that there are different objects (instances) of the same (persisted) object in the session. So normaly I would get an org.hibernate.NonUniqueObjectException, but I don’t get one.

So the question is, if this Exception is disabled per default in NHibernate? And if there is a property to set, so that nhibernate will be able to manage such things by it’s own? (don’t wanna write workarounds :) )

Thanks for your help,
Tobi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 2:30 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Looks like hibernate can't properly distinguish the instances. What kind of identity do you use ? Have you overwritten Equals() and GetHashCode() in your class ? Can you post the identity part of the mapping and the implementation of the class ? Maybe we can say more then.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 11:43 am 
Newbie

Joined: Wed Sep 17, 2008 5:44 am
Posts: 3
Hi,

thanks for your help, we're using Guids and the equals and hash code methods are not overwritten.

<id name="OrderId" column="OrderId" type="Guid">
<generator class="guid.comb" />
</id>

Don’t know if this is helpful?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 12:01 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look here:

http://www.nhforge.org/blogs/nhibernate/archive/2008/09/06/identity-field-equality-and-hash-code.aspx

I'm not absolutely sure if implementing Equals and GetHashCode solves your problem, but from your description it pretty much sounds like hibernate has problems distinguishing the instances. Looks like hibernate uses reference equality which is the reason why you don't get the expected exception.

_________________
--Wolfgang


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