org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
错误重现:
public class BaseDaoImpl<T,PK extends Serializable> extends HibernateDaoSupport implements IBaseDao<T,PK>{
private Session getCurrentSession() {
return this.getHibernateTemplate().getSessionFactory().getCurrentSession();
}
return this.getHibernateTemplate().getSessionFactory().getCurrentSession();
}
public Serializable save(T o) {
return this.getCurrentSession().save(o);
}
return this.getCurrentSession().save(o);
}
}
调用save时 报错。
解决方案:
return this.getCurrentSession().save(o); 改成 return this.getHibernateTemplate().save(o);
本文介绍了一种常见的Hibernate异常——无法在当前线程中获取到会话实例,并且配置不允许在此处创建非事务性的会话。针对此问题,提供了一个简单有效的解决方案。
1315

被折叠的 条评论
为什么被折叠?



