Hi all, 

i've got a hopefully simple question, cause my test is not running. Let's 
say, I had worked with NHibernate some years ago, and need some help to 
find the way to the framework again!

The following situation is captured from my test:


   1. The whole action is performed in a transaction (the transaction 
   covers the whole test)
   2. I have got two sessions. Session 1 loads some data using Linq, 
   Session 2 asserts an Navigation Property, that means loads data lazily.

It's clear to me that I need to detach my entities from session 1 and must 
attach the detached entities to session 2. But what is the way to do? I 
remember a method "SaveOrUpdateCopy" to attach entities to a session 
without reading the entity from the databse. But I can't find the method. 
For the Detachment, currently I am using the Evict method (and it looked 
well), but for the Attachment it seems like there are 3 possibilities



   - Lock 
   - Merge 
   - Update 
   
>From my understanding Lock is what I need, because Update will query 
changed from the database, and Merge seems to be an Update + Lock. But when 
I do, I get the following Exception:


NHibernate.LazyInitializationException : 
Initializing[Timecheck.DomainObjects.Enums.WorkingStatus.WorkingStatus#001b32e2-e103-4f2c-a3d7-ec89cd2f7b82]-Illegally
 
attempted to associate a proxy with two open Sessions

   bei 
NHibernate.Proxy.AbstractLazyInitializer.set_Session(ISessionImplementor 
value)
   bei 
NHibernate.Engine.StatefulPersistenceContext.ReassociateProxy(ILazyInitializer 
li, INHibernateProxy proxy)
   bei 
NHibernate.Engine.StatefulPersistenceContext.ReassociateIfUninitializedProxy(Object
 
value)
   bei NHibernate.Event.Default.ProxyVisitor.ProcessEntity(Object value, 
EntityType entityType)
   bei 
NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] 
values, IType[] types)
   bei 
NHibernate.Event.Default.AbstractReassociateEventListener.Reassociate(AbstractEvent
 
event, Object entity, Object id, IEntityPersister persister)
   bei NHibernate.Event.Default.DefaultLockEventListener.OnLock(LockEvent 
event)
   bei NHibernate.Impl.SessionImpl.FireLock(LockEvent lockEvent)
   bei NHibernate.Impl.SessionImpl.Lock(Object obj, LockMode lockMode)
   bei 
Timecheck.Persistence.NHibernate.Repositories.WorkingItemRepository.Attach(WorkingItem
 
item) 



That there are two sessions open is understandable. But I had evicted the 
entities from session 1, why the entities are sill part of session 1?

It would be greatful to get some help here. 


Thanks 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to