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,如下图所示




相关文章
|
资源调度
There appears to be trouble with your network connection.Retrying
There appears to be trouble with your network connection.Retrying
2053 0
There appears to be trouble with your network connection.Retrying
|
资源调度
yarn 错误:There appears to be trouble with your network connection. Retrying…
yarn 错误:There appears to be trouble with your network connection. Retrying…
1415 0
|
4月前
|
SQL Java
flywa报错Detected resolved migration not applied to database: 20221103.10000
flywa报错Detected resolved migration not applied to database: 20221103.10000
67 2
|
网络协议 Apache 开发工具