-->
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.  [ 8 posts ] 
Author Message
 Post subject: Strange Problem
PostPosted: Mon Sep 29, 2008 12:40 pm 
Newbie

Joined: Thu Jan 12, 2006 5:22 pm
Posts: 6
Hello,

We've been having a strange problem ever since we upgraded to NHibernate 2.0.0 (I upgraded today to 2.0.1 but the problem still persists). The problem is: sometimes, and I really mean sometimes, we have an exception like this one:

a different object with the same identifier value was already associated with the session: 0, of entity: OrionsBelt.DataAccessLayer.SpecializedExceptionInfo

Note that this only occurs when we throw an exception. After throwing, we try to store it on the DB creating a SpecialziedExceptionInfo to store the exception and using NHibernate to persist it.

Now, this exception only happens sometimes... we can stay all day long without it. When we start to have it, it usually happens for sometime, but if the restart the process everything works fine again.

More information about the problem pipeline:

» We are on an ASP.NET environment
» We open an NHibernate connection (if needed) on every request, and we dispose of it at the end of the request. All interaction with the DB on a given request is made using that connection
» If there's some exception we throw it, catch it, store it to a SpecializedExceptionInfo and persist it to the DB using NH
» If there's *another* exception, or sometimes another actions, we may get the problem I'm presenting

Can anyone help us?

Here's the full stack trace:

Code:
[NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of entity: OrionsBelt.DataAccessLayer.SpecializedExceptionInfo]
   NHibernate.Engine.StatefulPersistenceContext.CheckUniqueness(EntityKey key, Object obj) +170
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +630
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +452
   NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +144
   NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) +42
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) +128
   NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) +85
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) +199
   NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) +45
   NHibernate.Impl.SessionImpl.Save(Object obj) +44
   OrionsBelt.DataAccessLayer.NHibernatePersistance`1.Update(T t) in I:\psantos\Sirius\Trunk\DataAccessLayer\NHibernate\Persistance.cs:368
   OrionsBelt.DataAccessLayer.ExceptionLogger.Log(Exception ex) in I:\psantos\Sirius\Trunk\DataAccessLayer\Exceptions\ExceptionLogger.cs:26
   OrionsBelt.WebComponents.LanguageResources.Get(String key) in I:\psantos\Sirius\Trunk\WebComponents\Localization\LanguageResources.cs:60
   OrionsBelt.WebComponents.LanguageManager.Get(String language, String key) in I:\psantos\Sirius\Trunk\WebComponents\Localization\LanguageManager.cs:175
   OrionsBelt.WebComponents.LanguageManager.Get(String key) in I:\psantos\Sirius\Trunk\WebComponents\Localization\LanguageManager.cs:163
   OrionsBelt.WebUserInterface.Engine.WebUtilities.Compare(IResourceInfo r1, IResourceInfo r2) in I:\psantos\Sirius\Trunk\WebUserInterface\Engine\WebUtilities.cs:79
   System.FunctorComparer`1.Compare(T x, T y) +19
   System.Collections.Generic.ArraySortHelper`1.SwapIfGreaterWithItems(T[] keys, TValue[] values, IComparer`1 comparer, Int32 a, Int32 b) +125



Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 2:31 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Which id generator do you use ? Have you specified an unsaved-value ? The mapping might help.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 2:56 pm 
Newbie

Joined: Thu Jan 12, 2006 5:22 pm
Posts: 6
Hello,

We're using MySQL and the mapping goes like this:

Code:
<class      name="OrionsBelt.DataAccessLayer.SpecializedExceptionInfo, OrionsBelt.DataAccessLayer"
            table="ExceptionInfo"
            discriminator-value="-1039632119">
      <id name="Id" type="Int32" column="ExceptionInfoID">
         <generator class="native" />
      </id>
      <property name="Name" column="Name" type="String" length="15000" />
      <property name="Message" column="Message" type="String" length="15000" />
      <property name="Date" column="Date" type="DateTime"  />
      <many-to-one name="PrincipalNHibernate" column="PrincipalID" not-null="false" />
      <property name="Url" column="Url" type="String" length="15000" />
      <property name="StackTrace" column="StackTrace" type="String" length="15000" />
      <property name="CreatedDate" column="CreatedDate" type="DateTime"  />
      <property name="UpdatedDate" column="UpdatedDate" type="DateTime"  />
      <property name="LastActionUserId" column="LastActionUserId" type="Int32"  />
   </class>


Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 12:20 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hmm .. is it possible that you have overridden GetHashCode() and Equals() and that they are producing same results for objects that are not yet persisted (id=0) even if they are different objects.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 3:40 am 
Newbie

Joined: Thu Jan 12, 2006 5:22 pm
Posts: 6
Sometimes I have that exception like:

a different object with the same identifier value was already associated with the session: 23, of entity: OrionsBelt.DataAccessLayer.SpecializedExceptionInfo

It's not only with id=0. And we didn't redefined those methods.

I've read on the documentation that the increment generator could be troublesome when we have several processes updating the database, and we happen to to so...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 4:01 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
As long as the processes are not sharing a session this shouldn't be a problem. I can imagine a situation where you get this exception when you save an already persisted object (id>0). Then you should get this exception when you add different instances with the same id. But as long as the id is 0, hibernate should treat the object as unsaved and insert it into the database (in that case two records).

Can you post the code where you save/update the objects ?

Maybe try the nhusers list at google. Most of the developers are watching there.

http://groups.google.com/group/nhusers

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 11:03 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have you solved the problem or is the "point" for pointing you to the other mailing list ?

Just another question about your problem. The exception you are talking about is not a hibernate exception that occures during a session operation ? If that's the case the answer of Ayende is all you can do. But from your description I assumed that you are talking about arbitrary domain logig exceptions that you want to persist. Is that correct ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 12:15 pm 
Newbie

Joined: Thu Jan 12, 2006 5:22 pm
Posts: 6
Hello,

Well, we have it in those two ways: exceptions during session operations and exceptions from arbitrary logic we persist. However, we only get that error when we have an exception on a session operation.

I changed our code to "reset" the session whenever an exception occurs, and I'm monitoring the application to see if that does the trick.

Thank you for your help. :)


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