-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ILLEGAL ATTPT TO ASSOCIATE A COLLECTION WITH 2 OPEN SESSION
PostPosted: Mon Feb 20, 2006 12:59 am 
Beginner
Beginner

Joined: Mon Oct 17, 2005 1:58 am
Posts: 27
I using a single session to insert/update/delete data.But whenever I am trying to delete a record after insert it ,i get the nhibernate exception

ILLEGAL ATTEMPT TO ASSOCIATE A COLLECTION WITH TWO OPEN SESSIONS.

Although I am using the same session by reconnecting and disconnecting it everytime,I get this exeption while deleting.

Iam not opening and closing the session everytime as i think it will be a burden since the session will have to interact with the database again and again.

Can anybody tell me what is the problem and suggest any solution?


Top
 Profile  
 
 Post subject: Post Code please
PostPosted: Mon Feb 20, 2006 1:23 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
This exception is thrown from PersistentCollection class in the SetCurrentSession method. Following is the code:

Code:
public bool SetCurrentSession( ISessionImplementor session )
      {
         if( session == this.session )
         {
            return false;
         }
         else
         {
            if( IsConnectedToSession )
            {
               throw new HibernateException( "Illegal attempt to associate a collection with two open sessions" );
            }
            else
            {
               this.session = session;
               return true;
            }
         }
      }


If you can post the code that leads to the exception it would be helpful.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 1:39 am 
Beginner
Beginner

Joined: Mon Oct 17, 2005 1:58 am
Posts: 27
This is the base class delete function

protected void Delete(Object itemToDelete)
{

transaction = null;
try
{
if(!session.IsConnected)
session.Reconnect();

transaction = session.BeginTransaction();
session.Delete(itemToDelete);
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
finally
{
session.Disconnect();
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.