Problem with Primary key convention after updated to FNH 1.4.0.0

250 views
Skip to first unread message

Duncan Bradley

unread,
Apr 4, 2014, 8:51:19 AM4/4/14
to fluent-n...@googlegroups.com
I have just upgraded a project from FNH/NH version 1.2.0.694/3.0.0.4000 to 1.4.0.0/3.3.1.4000, and tests that were working fine with the old version now break.
The error is:
SetUp : NHibernate.NonUniqueObjectException : a different object with the same identifier value was already associated with the session: 0, of entity: 

My mappings are setup by convention:

public void Apply(FluentNHibernate.Conventions.Instances.IIdentityInstance instance)
        {
            instance.Column(instance.EntityType.Name + "Id");
            instance.GeneratedBy.Identity();
        }

The tests are failing when it saves a couple of domain objects on the second save, so I guess that it is not generating an identity column as per the convention. Debugging shows the id being changed to 0 on save of the first item.

Has there been a change between the 2 versions that would explain this, and any ideas on what I should do to fix?

Gleb Chermennov

unread,
Apr 5, 2014, 6:36:12 AM4/5/14
to fluent-n...@googlegroups.com
Can you do me a favor and try previous version of Fluent - 1.3.0.733 I think on Nuget - and tell me if the problem still there? That way I can pinpoint whether it's something we changed in 1.4 or it's an old bug. Thanks

Gleb Chermennov

unread,
Apr 5, 2014, 6:40:31 AM4/5/14
to fluent-n...@googlegroups.com
Also, can you post the complete code that cause the exception to appear?

Gleb Chermennov

unread,
Apr 5, 2014, 6:44:02 AM4/5/14
to fluent-n...@googlegroups.com

Duncan Bradley

unread,
Apr 7, 2014, 7:10:05 AM4/7/14
to fluent-n...@googlegroups.com
Thanks for your replies. 

I have reverted to v1.2.0.712 and the problem is not there. Upgrading to 1.3.0.717 and the problem occurs. So it looks like there was a change between 1.2 & 1.3 that makes the problem appear.

The tests initialise a nHibernate session:
 var config = Fluently.Configure()
                .Database(
                SQLiteConfiguration.Standard.ConnectionString(
            x => x.Is(mConnectionString)).Driver<SqliteDriver>().ShowSql());
    foreach (var assembly in assembliesWithMappings)
    {
   config.Mappings(                m =>                {                   m.FluentMappings.AddFromAssembly(assembly);                   m.FluentMappings.Conventions.AddAssembly(assembly);                 }            );            }       }
      var configuration = config.BuildConfiguration();
      BuildSchema(configuration);      mFactory = configuration.BuildSessionFactory();                 // Get the session     mSession = mFactory.OpenSession(GetConnection());

Then as part of the tests, it creates two persistence objects with slightly different data and saves:
DataPartition mDataPartition = DataPartitionTestObject.ValidDataPartition();
DataPartition mAnotherDataPartition = DataPartitionTestObject.ValidDataPartitionAlt();
 mDataPartitionRepository.Save(mDataPartition);
 mDataPartitionRepository.Save(mAnotherDataPartition); <== error
SetUp : NHibernate.NonUniqueObjectException : a different object with the same identifier value was already associated with the session: 0, of entity: Select.Domain.Persistence.DataPartition
   at NHibernate.Engine.StatefulPersistenceContext.CheckUniqueness(EntityKey key, Object obj)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.Save(Object obj)
When you look at the first object, the ID is set to 0, and so is the second. My test code can put an id into the object but it is reset to 0 on save.


On 5 April 2014 11:36, Gleb Chermennov <thebitt...@gmail.com> wrote:
Can you do me a favor and try previous version of Fluent - 1.3.0.733 I think on Nuget - and tell me if the problem still there? That way I can pinpoint whether it's something we changed in 1.4 or it's an old bug. Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Fluent NHibernate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fluent-nhibernate/vetRx7HF_gY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Gleb Chermennov

unread,
Apr 7, 2014, 7:24:44 AM4/7/14
to fluent-n...@googlegroups.com
So, you're saying that you explicitly set Id property to some value x, but after the Save method is called Id has value 0 in it?
That's odd. 
--
С уважением,
Чермённов Глеб, 

Duncan Bradley

unread,
Apr 7, 2014, 7:32:27 AM4/7/14
to fluent-n...@googlegroups.com
Yes. But in 1.2.0 it operates as expected...the first one gets ID1, the second ID 2. 
Have you any notes on upgrading 1.2 to 1.3 that I need to read? Or is it a change in nHibernate?

Thanks

Gleb Chermennov

unread,
Apr 7, 2014, 8:19:02 AM4/7/14
to fluent-n...@googlegroups.com
I assume your version of NHibernate is the same whether you use Fluent 1.3.x or 1.2.x. If that's the case, it sounds like it's Fluent NHibernate problem. If itsn't, you can look at their release notes.
Unfortunately, I don't have a list of changes between versions - not yet. Let me take a look at it and see what I can do.


--
You received this message because you are subscribed to a topic in the Google Groups "Fluent NHibernate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fluent-nhibernate/vetRx7HF_gY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Duncan Bradley

unread,
Apr 7, 2014, 8:32:16 AM4/7/14
to fluent-n...@googlegroups.com
I am using the version of nHibernate that your package specifies. I let it do everything via nuget.

Gleb Chermennov

unread,
Apr 7, 2014, 9:28:17 AM4/7/14
to fluent-n...@googlegroups.com
You mean the default version - the latest, 3.3.3.4001?

Duncan Bradley

unread,
Apr 7, 2014, 10:24:29 AM4/7/14
to fluent-n...@googlegroups.com
FNH 1.2.0.712 uses 3.1.0.4000 NH  Works OK
FNH 1.3.0.717 uses 3.2.0.4000 NH Fails
FNH 1.3.0.727 uses 3.3.0.4000 NH Fails

Gleb Chermennov

unread,
Apr 7, 2014, 10:52:38 AM4/7/14
to fluent-n...@googlegroups.com
I see.
Out of curiosity, please try Fluent v1.3.0.717 with NHibernate 3.1.0.4000 - if that fails, it must be Fluent bug between 1.2 and 1.3.


--
You received this message because you are subscribed to a topic in the Google Groups "Fluent NHibernate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fluent-nhibernate/vetRx7HF_gY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Duncan Bradley

unread,
Apr 7, 2014, 11:53:47 AM4/7/14
to fluent-n...@googlegroups.com
After a bit of playing around, I got nHibernate 3.1.0.4000 installed, and then upgraded Fluent without the dependencies.
Got the following error on recompile:
Error 1 Assembly 'FluentNHibernate, Version=1.3.0.717, Culture=neutral, PublicKeyToken=8aa435e3cb308880' uses 'NHibernate, Version=3.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' which has a higher version than referenced assembly 'NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'

I tried a binding redirect:
<bindingRedirect oldVersion="0.0.0.0-3.3.3.4000" newVersion="3.1.0.4000" />
without any success....same error. So I cannot try out your suggestion

Gleb Chermennov

unread,
Apr 7, 2014, 4:45:32 PM4/7/14
to fluent-n...@googlegroups.com
I've managed to pry list of issues between 1.2 and 1.3 releases out of Github. All dates are in UTC. As far as I can tell, there were no changes regarding your problem. 

Id: 14; Name: Upgraded to NHibernate 3.1; Created: Friday, March 11, 2011 11:55 AM; Closed: Sunday, April 03, 2011 10:50 AM; Author: danielmarbach
Id: 20; Name: Bug: Explicit MetaType clears out MetaValues; Created: Monday, April 04, 2011 7:15 PM; Closed: Tuesday, June 14, 2011 6:51 PM; Author: andreialecu
Id: 21; Name: implemented list-index with baseoffset for lists; Created: Tuesday, April 12, 2011 7:45 PM; Closed: Tuesday, August 09, 2011 2:44 PM; Author: firo222
Id: 22; Name: PersistenceSpecification in a TransactionScope; Created: Monday, April 18, 2011 12:08 PM; Closed: Thursday, August 11, 2011 6:02 PM; Author: jochenjonc
Id: 24; Name: Extension method overloads for PersistenceSpecification; Created: Friday, May 27, 2011 8:57 PM; Closed: Tuesday, June 14, 2011 6:51 PM; Author: RyanHauert
Id: 25; Name: Fix for UseUnionSubclassForInheritanceMapping not working with AutoMapping; Created: Monday, May 30, 2011 5:50 PM; Closed: Tuesday, June 14, 2011 6:51 PM; Author: Gutek
Id: 26; Name: Added MultipleActiveResultSets for MsSqlConnectionStringBuilder; Created: Thursday, June 16, 2011 6:33 PM; Closed: Tuesday, August 09, 2011 12:09 PM; Author: ermau
Id: 27; Name: Fix for issue #216 - override scanning mishandles abstract overrides ; Created: Wednesday, June 29, 2011 7:27 PM; Closed: Thursday, June 30, 2011 6:33 PM; Author: icambron
Id: 28; Name: Fix for issue #216 - override scanning mishandles abstract overrides ; Created: Thursday, June 30, 2011 6:38 PM; Closed: Tuesday, August 09, 2011 2:49 PM; Author: icambron
Id: 29; Name: added convenience for adding filters to automaps; Created: Monday, July 04, 2011 7:09 PM; Closed: Tuesday, August 09, 2011 2:52 PM; Author: icambron
Id: 30; Name: Ingres database configuration; Created: Wednesday, July 06, 2011 2:53 AM; Closed: Tuesday, August 09, 2011 2:57 PM; Author: tangbiao
Id: 31; Name: exposed the entity type from ToManyBase; Created: Thursday, July 07, 2011 12:14 AM; Closed: Tuesday, August 09, 2011 3:09 PM; Author: icambron
Id: 32; Name: Specifying cascading foreign key in auto mapping; Created: Tuesday, July 12, 2011 6:53 PM; Closed: Tuesday, August 09, 2011 3:13 PM; Author: sonix1977nl
Id: 33; Name: Add XML documentation output; Created: Wednesday, July 20, 2011 3:10 PM; Closed: Tuesday, August 09, 2011 5:19 PM; Author: ngbrown
Id: 34; Name: Override scanning seems to try to instantiate abstract classes; Created: Thursday, July 21, 2011 10:17 PM; Closed: Wednesday, July 27, 2011 8:13 AM; Author: jagregory
Id: 39; Name: Inverse validation fails on self-referential relationships ; Created: Thursday, July 21, 2011 10:23 PM; Closed: Friday, January 27, 2012 9:45 PM; Author: jagregory
Id: 76; Name: Reset master to v1.x; Created: Thursday, July 21, 2011 11:39 PM; Closed: Tuesday, August 09, 2011 5:37 PM; Author: jagregory
Id: 77; Name: Not the prettiest code, but I had to do some juggling to get the default overriding correct. Let me know if it can be done better.; Created: Saturday, July 23, 2011 9:19 PM; Closed: Tuesday, August 09, 2011 5:29 PM; Author: benfulton
Id: 79; Name: Moved ability to add overrides by type to the AutoPersistenceModel; Created: Tuesday, August 02, 2011 9:12 PM; Closed: Thursday, August 11, 2011 6:01 PM; Author: icambron
Id: 80; Name: Failed test for check that component Column name convention does not brok; Created: Wednesday, August 03, 2011 4:41 AM; Closed: Thursday, August 11, 2011 6:36 PM; Author: hazzik
Id: 81; Name: Added missed reference to System.Transactions; Created: Thursday, August 11, 2011 6:18 PM; Closed: Friday, August 12, 2011 11:04 AM; Author: hazzik
Id: 82; Name: Failed test for check that component Column name convention does not brok; Created: Thursday, August 11, 2011 6:36 PM; Closed: Friday, August 12, 2011 6:24 PM; Author: hazzik
Id: 83; Name: FIX for : https://github.com/jagregory/fluent-nhibernate/issues/45; Created: Tuesday, August 16, 2011 11:56 AM; Closed: Sunday, October 02, 2011 6:17 PM; Author: MarkJPerry
Id: 87; Name: Added readme file and tweaked RakeFile; Created: Tuesday, August 30, 2011 2:12 PM; Closed: Sunday, October 02, 2011 6:18 PM; Author: asbjornu
Id: 88; Name: Fix for issue #39 and also covers #53.; Created: Thursday, September 01, 2011 5:41 PM; Closed: Sunday, October 02, 2011 6:18 PM; Author: hazzik
Id: 90; Name: Small fix in Property.GetInequalityComparisonMessage(); Created: Monday, September 12, 2011 1:55 PM; Closed: Sunday, October 02, 2011 6:19 PM; Author: RyanHauert
Id: 91; Name: Added generic version of `ChildWhere` for many-to-many part.; Created: Monday, September 12, 2011 3:10 PM; Closed: Sunday, October 02, 2011 6:20 PM; Author: hazzik
Id: 92; Name: added ability to set a custom type on composite keys; Created: Tuesday, September 13, 2011 7:21 PM; Closed: Sunday, October 02, 2011 6:21 PM; Author: icambron
Id: 93; Name: FNH 1.3: Mapping to the ICompositeUserType broken; Created: Friday, September 16, 2011 12:56 PM; Closed: Tuesday, September 20, 2011 1:11 PM; Author: sergey-legenkiy
Id: 94; Name: fixed: cant change from bag to list in convention; Created: Tuesday, September 20, 2011 8:02 PM; Closed: Sunday, October 02, 2011 6:22 PM; Author: firo222
Id: 95; Name: Fix performance issue searching in list of 'availableTypes'. GetLogicalPa; Created: Monday, September 26, 2011 7:41 PM; Closed: Sunday, October 02, 2011 6:23 PM; Author: mbp
Id: 96; Name: Remove obsolete method which has been obsolete since 2010-12-26 11:53:09,; Created: Monday, September 26, 2011 8:07 PM; Closed: Sunday, October 02, 2011 6:23 PM; Author: mbp
Id: 97; Name: Filter condition applied to name; Created: Monday, September 26, 2011 8:19 PM; Closed: Sunday, October 02, 2011 6:23 PM; Author: mbp
Id: 98; Name: Added ability to set key as (not)nullable via convention; Created: Thursday, September 29, 2011 4:23 PM; Closed: Sunday, October 02, 2011 6:24 PM; Author: hazzik
Id: 99; Name: Fixed Formula with ManyToOne; Created: Thursday, September 29, 2011 10:11 PM; Closed: Sunday, October 02, 2011 6:24 PM; Author: MaciejSzczepanski
Id: 100; Name: Added OtherSide property to one-to-many; Created: Saturday, October 01, 2011 4:55 AM; Closed: Sunday, October 02, 2011 6:24 PM; Author: hazzik
Id: 103; Name: Example projects throw run time exceptions because of private setters on ID properties; Created: Tuesday, October 11, 2011 7:40 PM; Closed: Saturday, December 10, 2011 11:28 PM; Author: tbushell
Id: 108; Name: Added cascade.merge option; Created: Wednesday, November 09, 2011 2:01 PM; Closed: Saturday, December 10, 2011 11:29 PM; Author: tchrikch
Id: 112; Name: Changed the Id setters visibility to protected in the Examples.; Created: Saturday, December 10, 2011 10:52 PM; Closed: Saturday, December 10, 2011 11:28 PM; Author: Saulis
Id: 116; Name: Fix for Issue #110; Created: Wednesday, December 28, 2011 10:26 PM; Closed: Friday, January 27, 2012 9:42 PM; Author: firo222
Id: 117; Name: InstallGems.bat - installing right version of albacore; Created: Thursday, January 05, 2012 7:11 PM; Closed: Friday, April 27, 2012 12:57 AM; Author: hazzik
Id: 131; Name: Nuget package contains intellisense file instead of pdb; Created: Thursday, April 05, 2012 3:41 PM; Closed: Friday, April 27, 2012 12:57 AM; Author: citizenmatt
Id: 132; Name: Migrate to NH 3.3; Created: Friday, April 27, 2012 12:34 AM; Closed: Friday, April 27, 2012 1:10 AM; Author: jagregory
Id: 135; Name: CustomType does not work for IIdConventions; Created: Tuesday, May 15, 2012 7:52 PM; Closed: Tuesday, May 15, 2012 8:29 PM; Author: alberto-chiesa
Id: 142; Name: FluentNHibernate Reference in VS2010: ISession unknown; Created: Wednesday, June 06, 2012 6:16 PM; Closed: Wednesday, June 06, 2012 6:46 PM; Author: mwpowellhtx


I'd like to get a list of commits too - but it requres a bit more work, will do that tomorrow.


--
You received this message because you are subscribed to a topic in the Google Groups "Fluent NHibernate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fluent-nhibernate/vetRx7HF_gY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages