org.hibernate.sessionexception会话已关闭

时间:2015-03-17 11:04:30

标签: hibernate

我正在使用Hibernate,当我执行更新时,它给了我这个例外: -

org.hibernate.SessionException: Session is closed!

2015-03-17 17:04:54,541 1412797 ERROR [stderr] (http-0.0.0.0-0.0.0.0-8080-2:)   at org.hibernate.internal.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:127)

2015-03-17 17:04:54,542 1412798 ERROR [stderr] (http-0.0.0.0-0.0.0.0-8080-2:)   at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:753)

2015-03-17 17:04:54,544 1412800 ERROR [stderr] (http-0.0.0.0-0.0.0.0-8080-2:)   at org.hibernate.internal.SessionImpl.save(SessionImpl.java:749)

2015-03-17 17:04:54,545 1412801 ERROR [stderr] (http-0.0.0.0-0.0.0.0-8080-2:)   at org.hibernate.internal.SessionImpl.save(SessionImpl.java:745)

以下是我的代码

public void update(Rest rest){ 
    Setting settdao = new Setting();
    Transaction tr = null;   
try {
        Session session=getSession();
        tr = session.beginTransaction();
        session.update(rest);
        settdao.addSub(rest,session);
        tr.commit();
        log.debug("update successful");
    } 
catch(Exception e)
    {
         e.printstacktrace();  
    }

上面的update()方法中的addSub()方法: -

private int addSub(Rest rest, Session session) {
try {
       session.save(rest);  //Here,I get the Hibernate exception.
    }

catch(Exception e)
    {
       e.printstacktrace();  
    }
 return 1; 
}

我错了吗?可能是什么原因。请帮忙。

0 个答案:

没有答案