Try using SaveOrUpdate instead of just Update John Davidson
On Wed, Jun 2, 2010 at 4:34 AM, Deepraj <[email protected]> wrote: > HI All, > > 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(ISessionImplementor > 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(AbstractEvent > event, Object entity, Object id, IEntityPersister persister) > at > > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformUpdate(SaveOrUpdateEvent > event, Object entity, IEntityPersister persister) > at > > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsDetached(SaveOrUpdateEvent > event) > at > > NHibernate.Event.Default.DefaultUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent > event) > at > > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent > 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 not null value is checked inorder to > create a new session factory. > > private static ISessionFactory _sessionFactory; > > public static ISessionFactory SessionFactory > { > get > { > if (_sessionFactory == null) > { > Configuration configuration = new Configuration(); > configuration.Configure(); > ................... > } > } > } > > > After creating the session, a 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.ProxyFactoryFactory, > 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> > > 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 > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
