首页 > 代码库 > No CurrentSessionContext configured

No CurrentSessionContext configured

今天编写hibernate程序碰到这个问题:

   Exception in thread "main"org.hibernate.HibernateException:No CurrentSessionContext configured!

   atorg.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:698)

   atcom.HibernateProxy.Interceptor.MyTransactor.beginTransaction(MyTransactor.java:13)

   atcom.HibernateProxy.Interceptor.PersonDaoInterceptor.invoke(PersonDaoInterceptor.java:22)

   atcom.sun.proxy.$Proxy0.savePerson(Unknown Source)

   atcom.HibernateProxy.test.Test.main(Test.java:28)

解决方法为:

打开hibernate.cfg.xml文件,添加如下代码:

   <propertyname="current_session_context_class">thread</property>

或者用Myeclipse hibernate config editor打开hibernate.cfg.xml,添加current_session_context_class,如下图所示

技术分享



No CurrentSessionContext configured