最近在搞汤老师的BBS ,我在测试的时候遇到了org.hibernate.HibernateException: No CurrentSessionContext configured!错误。。。找了半天,在百度上才发现是什么原因。。。
初学hibernate,出现No CurrentSessionContext configured错误,检查了几次配置都没有发现问题,最后上网查找发现是配置文件的问题 在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入: 终于搞定了。。。通过这个可以发现,学习软件开发是需要日积月累的。。。。更应正了一句最经典的话,,程序员是在错误中长大的!
解决如下:
在集成Hibernate的环境下(例如Jboss),在hibernate.cfg.xml中session-factory段加入:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
private static SessionFactory sessionFactory ;
static{
configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
}
public static Session getSession(){
return sessionFactory.getCurrentSession();
}
org.hibernate.HibernateException: No CurrentSessio
最新推荐文章于 2019-03-26 12:09:46 发布

<property name="current_session_context_class">jta</property>
<property name="current_session_context_class">thread</property>
加入了这句话什么测试类就可以运行了。。。。
哎,这个错误我记忆尤深那。。。。
这个就是需要配置的代码:
import org.hibernate.Session;
public class HibernateSessionFactory {
private static final Configuration configuration ;