Hi Deepraj,

This is the group for NH developers. Please use the users group: http://groups.google.com/group/nhusers


After creating the session, the assemblies that is placed in a

Also, you might want to review your code to make sure you add the assemblies to the configuration before creating the session factory.

Cheers,
   Richard

--------------------------------------------------
From: "Deepraj" <[email protected]>
Sent: Thursday, June 03, 2010 5:42 AM
To: "nhibernate-development" <[email protected]>
Cc: <[email protected]>
Subject: [nhibernate-development] Illegal attempt to associate a collection with two open sessions

When I try to update the entity using NHibernate, I am getting the
error as follows


"Illegal attempt to associate a collection with two open sessions"


Find below the stack trace


  at
NHibernate.Collection.AbstractPersistentCollection.SetCurrentSession(ISessi­
onImplementor
session)
  at NHibernate.Event.Default.OnLockVisitor.ProcessCollection(Object
collection, CollectionType type)
  at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Object
value, IType type)
  at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Int32 i,
Object[] values, IType[] types)
  at
NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object­
[]
values, IType[] types)
  at NHibernate.Event.Default.AbstractVisitor.Process(Object obj,
IEntityPersister persister)
  at
NHibernate.Event.Default.AbstractReassociateEventListener.Reassociate(Abstr­
actEvent
event, Object entity, Object id, IEntityPersister persister)
  at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformUpdate(Sav­
eOrUpdateEvent
event, Object entity, IEntityPersister persister)
  at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsDetached(­
SaveOrUpdateEvent
event)
  at
NHibernate.Event.Default.DefaultUpdateEventListener.PerformSaveOrUpdate(Sav­
eOrUpdateEvent
event)
  at
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(Sa­
veOrUpdateEvent
event)
  at NHibernate.Impl.SessionImpl.FireUpdate(SaveOrUpdateEvent event)
  at NHibernate.Impl.SessionImpl.Update(Object obj)
  at CS3Repository.PreRegHeaderRepository.EditPreRegHeader(ISession
session, PreRegHeader PreRegHeaderToUpdate) in E:\generate
\PersistentClasses\Temp\CS3Entities\Repository
\PreRegHeaderRepository.cs:line 153
  at
RegEvntServiceBase.RegEvntServiceBase.EditPreRegHeader(PreRegHeader
PreRegHeaderToEdit) in E:\generate\PersistentClasses\Temp\RegEvnt
\RegEvntService\RegEvntServiceBase.cs:line 102


Given below is my code


I am opening a session like this


ISession session = nHibernateHelper.OpenSession();


Inside nHibernateHelper, a static variable is used to create the
session factory and each time null value is checked inorder to create
a new session factory.

Code:

private static ISessionFactory _sessionFactory;


public static ISessionFactory SessionFactory
       {
           get
           {
               if (_sessionFactory == null)
               {
                   Configuration configuration = new
Configuration();
                   configuration.Configure();
                   ...................
               }
            }
         }


After creating the session, the assemblies that is placed in a
specific folder is added to the configuration object
like below.

files = Directory.GetFiles(src, "*Entities.dll");


foreach (string file in files)
{
       Assembly assembly = Assembly.LoadFrom(file);
       configuration.AddAssembly(assembly);
}

call is made to open a transaction
and then the update statement is executed like


session.Update(...);


Also these are the settings in hibernate.config.xml


<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
   <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</
property>
   <property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
   <property
name="connection.connection_string">Server=DevServer;initial
catalog=SportsDB;Trusted_Connection=True</property>
   <property name="show_sql">false</property>
   <property
name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFa­
ctory,
NHibernate.ByteCode.Castle</property>
   <property  name="current_session_context_class">web</property>
   <property name='adonet.batch_size'>20</property>
   <property
name='cache.provider_class'>NHibernate.Cache.HashtableCacheProvider</
property>
   <property name='cache.use_query_cache'>true</property>
   <property name='default_schema'>SportsDB.dbo</property>
   <property name='connection.isolation'>ReadCommitted</property>


Also note that cascade = All is given the mapping files..


<set name="PreRegVols" cascade="all" lazy="true" inverse="true"
batch-
size="4">
<...>
</set>

But for many-to-one mapping, this is not used. There cascade = 'none"
is specified.

On seeing a post I removed cascade ="all" from the set tag, but the
result is same.

Please help me on this. This is urgent.

Thanks in advance,


Deepraj D


Reply via email to