-->
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.  [ 4 posts ] 
Author Message
 Post subject: Illegal attempt to associate a collection with two open sess
PostPosted: Mon Jan 30, 2006 12:29 pm 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Im getting this exception when calling my update DAO method.

NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions.

Im getting an object with this:


Code:
protected Object get(Object ob,int id)
      {   
         try
         {
            ISessionFactory factory = NHibernateSessionFactory.getFactory();
            
            ISession session = factory.OpenSession();

            return session.Get(ob.GetType(),id);

         }
         finally
         {
            if(session != null)
               session.Close();
         }
      }



Then im up dateing it like this:
Code:
private void subButton_Click(object sender, System.EventArgs e)
      {
         String id = Request.QueryString.Get("Id");
         FairDAO fairDAO = new FairDAO();

         Fair f = fairDAO.get(id);
         f.Code=Convert.ToInt32(id);
         f.Description=desp.Text;
         f.StartingDate = new DateTime(   Convert.ToInt32(dateY.Text),
            Convert.ToInt32(dateM.Text),
            Convert.ToInt32(dateD.Text));
         f.Duration=Convert.ToInt32(duration.Text);
         f.Title=title.Text;
         f.SponsorCode=Convert.ToInt32(sponsor.Text);

         fairDAO.updateFair(f);

         Response.Redirect("staffAdmin.aspx");
      }



and then persisting it like this:

Code:
protected void update(Object o)
      {   
         try
         {
            ISessionFactory factory = NHibernateSessionFactory.getFactory();
            
            ISession session = factory.OpenSession();

            ITransaction transaction = session.BeginTransaction();

            session.Update(o);

            transaction.Commit();
            session.Close();
         }
         catch
         {
            if(transaction != null)
               transaction.Rollback();
            throw;
         }
         finally
         {
            if(session != null)
               session.Close();
         }

      }


I cant see how here is 2 open sessions, im closeing the sessions, and dedugging in VS Confirms this


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 5:59 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
you guys have any idea about this?


Top
 Profile  
 
 Post subject: Re: Illegal attempt to associate a collection with two open
PostPosted: Tue Jan 31, 2006 6:35 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:

Code:
protected Object get(Object ob,int id)
      {   
         try
         {
            ISessionFactory factory = NHibernateSessionFactory.getFactory();
            
            ISession session = factory.OpenSession();

            return session.Get(ob.GetType(),id);

         }
         finally
         {
            if(session != null)
               session.Close();
         }
      }




I can only comment this pattern You are using:
If You declare a new variable inside try block, it is not visible inside finally block. So:
1. You have some other variable/field/property named session that is closed in finally block. Hence, the session opened inside try block remains endeed opened and the error is correct.
2. You did post code that is not compiling.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 6:42 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Thank you!! Quite Obvious now that i look at it, been staring at it for a while and never seen it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.