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);