A different object with the same identifier value was already associated with the session: XXXX

Topics: Developer Forum
Dec 13, 2008 at 3:05 PM
Edited Dec 13, 2008 at 3:22 PM
I've just updated from version 1.4.3.2 to 1.4.4.
After upgrading I keep getting this error message everytime I try to save an item:

a different object with the same identifier value was already associated with the session: 2374, of entity: N2.Details.LinkDetail

The problem seems to be related to MySQL. In my development enviroment, where I use sql express 2005, I do not get the error.
Does anyone else get this error or know how to avoid this problem? 

Stack Trace:

[NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 2374, of entity: N2.Details.StringDetail]
   NHibernate.Engine.StatefulPersistenceContext.CheckUniqueness(EntityKey key, Object obj) +149
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +596
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +345
   NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +144
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) +26
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) +81
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) +85
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) +206
   NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event) +46
   NHibernate.Impl.SessionImpl.SaveOrUpdate(String entityName, Object obj) +49
   NHibernate.Engine.SaveUpdateCascadingAction.Cascade(IEventSource session, Object child, String entityName, Object anything, Boolean isCascadeDeleteEnabled) +74
   NHibernate.Engine.Cascade.CascadeToOne(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) +103
   NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) +73
   NHibernate.Engine.Cascade.CascadeProperty(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) +104
   NHibernate.Engine.Cascade.CascadeCollectionElements(Object child, CollectionType collectionType, CascadeStyle style, IType elemType, Object anything, Boolean isCascadeDeleteEnabled) +351
   NHibernate.Engine.Cascade.CascadeCollection(Object child, CascadeStyle style, Object anything, CollectionType type) +175
   NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) +136
   NHibernate.Engine.Cascade.CascadeProperty(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled) +104
   NHibernate.Engine.Cascade.CascadeOn(IEntityPersister persister, Object parent, Object anything) +370
   NHibernate.Event.Default.AbstractSaveEventListener.CascadeAfterSave(IEventSource source, IEntityPersister persister, Object entity, Object anything) +84
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +771
   NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +345
   NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) +144
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) +26
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) +81
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) +85
   NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) +206
   NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event) +46
   NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) +47
   N2.Persistence.NH.NHRepository`2.SaveOrUpdate(TEntity entity) +27
   N2.Persistence.VersionManager.SaveVersion(ContentItem item) +372
   N2.Edit.EditManager.SaveVersion(ContentItem current) +55
   N2.Edit.EditManager.Save(IItemEditor itemEditor, IPrincipal user) +634
   N2.Web.UI.WebControls.ItemEditor.Save() +64
   N2.Edit.Edit.SaveVersion() +70
   N2.Edit.Edit.OnSaveUnpublishedCommand(Object sender, CommandEventArgs e) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +108
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Coordinator
Dec 13, 2008 at 3:51 PM
A theory is that the link tracker does something wrong. It stores an additional database references to pages being linked in text content. Can try to find a reliable way to reproduce the problem on http://templates.n2cms.com/. The site uses mysql. Thanks.
Dec 15, 2008 at 7:44 PM
Edited Dec 15, 2008 at 7:45 PM
I've just tried to make a fresh install of the "Templates Sample Project" version 1.4.4 (running MySQL v5.0.67).
This also produce the error!

There's no problem creating items (pages) but as soon as I edit an item and click save, I get the error in my first post.
Here's a screenshot of the error...
Coordinator
Dec 15, 2008 at 10:29 PM
Okay, I managed to reproduce this. I'll see what I can do.
Coordinator
Dec 16, 2008 at 11:14 PM
I've tried tracking this down. So far I've done random experiments. Could you try this combination of dll's and see if you still reproduce the problem?
Dec 17, 2008 at 7:23 AM

The new set of dll’s didn’t solve the problem… the exception is still thrown every time I update an item.

Thank you for working on the issue!

Coordinator
Dec 17, 2008 at 8:03 PM
Okay, I'll continue looking. In the meantime you could delete not published versions from the version list or disable versioning (<n2><edit enableVersioning="false">)
Dec 17, 2008 at 9:21 PM
I disabled versioning as you suggested - works perfect!
I'm looking forward to the "final solution". Let me know when to do some more testing :)

Again thank you for the quick help.
Coordinator
Dec 20, 2008 at 10:30 PM
I did some changes related to transactions. Would you mind trying the dlls again and see whether it solves the problem? Thanks
Dec 21, 2008 at 9:47 PM
Hi libardo

I've tried to test the update, but I'm having some problems.
After uploading the update I get the following error:

Could not load file or assembly 'NHibernate, Version=2.0.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The updated files contains a newer version of Nhibernate (v. 2.0.1.4000).
But uploading version 2.0.0.4000 does not solve the problem. Then the following exception is thrown insted:

Could not load file or assembly 'NHibernate, Version=2.0.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Coordinator
Dec 22, 2008 at 10:47 AM
Do you referencing nhibernate from any project? If so, could you update the reference to use the later version and recompile?

To force the newer version without recompiling you could do like this:
    <runtime>
            <dependentAssembly>
                <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
                <bindingRedirect oldVersion="2.0.0.4000-2.0.1.4000 " newVersion="2.0.1.4000 "/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
Dec 26, 2008 at 9:19 AM
Edited Dec 26, 2008 at 9:20 AM
I tried to force N2 to use the newer version of Nhibernate as you suggested... N2 still throws the same exception.

<configuration>
    
<
runtime>
        <
dependentAssembly>
            <
assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral">
                <
bindingRedirect oldVersion="2.0.0.4000" newVersion="2.0.1.4000"/>
            </
assemblyIdentity>
        </
dependentAssembly>
    </
runtime>
</
configuration>

 

 

I am testing using the N2 Example Templates Site without any modifications.

Apr 23, 2009 at 4:50 AM
Hi All,

Did anyone figure out why this was happening? I am getting the exact same problem.
Thanks,
Coordinator
Apr 23, 2009 at 5:53 PM
Which of the errors are you referring to exactly?

"A different object with the same identifier" or "Could not load file or assembly 'NHibernate"?

The first might be caused by a (by me) unexcepected behaviour when using multiple transactions with mysql. I think this is fixed now.

The second would be caused by assemblies referencing different versions of nhibernate.dll. You could debug this by opening the dlls in /bin with reflector and looking at the references.
Apr 23, 2009 at 11:49 PM
I am talking about this one.

[NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 2374, of entity: N2.Details.StringDetail]
Id generation works for MS Sql but the same code does not work for MySql. Also, if I plugin a custom Id generator it works.
Coordinator
Apr 24, 2009 at 11:41 PM
Can you post a stack trace? I'd like to understanding where this is originating.