NHibernate version 1.2.0.4
wtih reference to issue logged at
http://jira.nhibernate.org/browse/NH-401
Entities : Individual And User
as per the issue at above link the following bug has been fixed:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Configuration cfg = new Configuration();
cfg.AddAssembly("DataAccess");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession sess = factory.OpenSession();
ISession sess2 = factory.OpenSession();
Individual ind = new Individual();
ind.ProfileId = 872; //id from my db ...
ind.Last = "XC"
ind.CreatedBy = ses2.Get<User>(1);
ITransaction trans = sess.BeginTransaction();
sess.SaveOrUpdateCopy(mem);
trans.Commit();
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
here the issue was it threw NonUniqueObjectException exception SaveOrUpdate(), as I used User's object that was loaded using other session object and tried to save Individual object using another session object.
This has been fixed.
But the following one line change to above snippet again throws the same exception.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Configuration cfg = new Configuration();
cfg.AddAssembly("DataAccess");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession sess = factory.OpenSession();
User user = sess.Get<User>(1);
ISession sess2 = factory.OpenSession();
Individual ind = new Individual();
ind.ProfileId = 872; //id from my db ...
ind.Last = "XC"
ind.CreatedBy = ses2.Get<User>(1);
ITransaction trans = sess.BeginTransaction();
sess.SaveOrUpdateCopy(mem);
trans.Commit();
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any idea why does this happen?
Also as an temporary fix I have commented out CheckUniqueness(EntityKey key, object obj) function call from function DoUpdateMutable and it is working fine. Though I am not sure whether this will affect any other scenario, please advise.