-->
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.  [ 6 posts ] 
Author Message
 Post subject: "Session is closed" exception
PostPosted: Tue Mar 22, 2005 8:34 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
Hi,

Can someone please help me with this "Session is closed" exception"?

I am trying to write the change of my User class to the database, like this:

Code:
    UAProfile profile = getCurrentProfile();
                     
            UAProfile  profile2 = findCurrentProfile();

            UserProfileDAO usdao = new UserProfileDAO();
            profile2.setScreenHeight(profile.getScreenHeight());
           
            usdao.makePersistent(profile2);
           
            HibernateUtil.commitTransaction();


And in the findCurrentProfile(), I open and close the session. Why I get teh Session is closed exception? Can someone please help?

Thank you.

Code:
private UAProfile findCurrentProfile() {
        UserProfileDAO userProfileDao = new UserProfileDAO();
        try {
            UAProfile ua = userProfileDao.getUAProfileByName(getPath());
            return ua;
        } catch (HibernateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                HibernateUtil.closeSession();
            } catch (HibernateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }



Code:
net.sf.hibernate.HibernateException: Session is closed
   at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3339)
   at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86)
   at db.HibernateUtil.rollbackTransaction(HibernateUtil.java:207)
   at db.HibernateUtil.commitTransaction(HibernateUtil.java:192)
   at net.sf.tacos.demo.tree.fs.FileTreePage.change(FileTreePage.java:136)



Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 8:44 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
and if I change my calls from closeSession to disconnectSession(). I got this
Illegal attempt to associate a collection with two open sessions? Why I have 2 open sessions? I think I have disconnect one before I reopen another one.

Thank you.

net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at net.sf.hibernate.collection.PersistentCollection.setCurrentSession(PersistentCollection.java:257)
at net.sf.hibernate.impl.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:38)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.AbstractVisitor.process(AbstractVisitor.java:91)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 4:57 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Well - you are closing the session in findCurrentProfile() and then trying to commit an addition in the calling method (after the session is closed). Close the session at the end of your work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 11:41 am 
Newbie

Joined: Tue Mar 22, 2005 5:43 pm
Posts: 16
Location: Teksouth
can you post you code from
usdao.makePersistent(profile2);
You may not be opening the session before saving the data.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 6:08 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
Thanks.

But I did call "new UserProfileDAO()" before calling "makePersistent()",
and in the constructor of UserProfileDAO, I did a call a "HibernateUtil.beginTransaction();"

Code:

    UserProfileDAO usdao = new UserProfileDAO();
            profile2.setScreenHeight(profile.getScreenHeight());
           
            usdao.makePersistent(profile2);


Is that sufficient?

As I mention earlier, I change from "closeSession() " to "disconnectSession", I just get a different exception.

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 6:12 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
drj wrote:
Well - you are closing the session in findCurrentProfile() and then trying to commit an addition in the calling method (after the session is closed). Close the session at the end of your work.


Thanks. But is it possible I re-open a new session again after I close it?

I did a new UserProfileDAO(); and in the constructor, it begins a new tansaction.



Code:
  UAProfile  profile2 = findCurrentProfile();
            UserProfileDAO usdao = new UserProfileDAO();
            profile2.setScreenHeight(profile.getScreenHeight());
           
            usdao.makePersistent(profile2);
           

            HibernateUtil.commitTransaction();



Thank you for any help.
Sam


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