No value for key [org.hibernate.impl.SessionFactoryImpl 异常解决
2014-07-24 13:38
633 查看
使用Hibernate+Spring进行CRUD操作时,出现如下类似异常信息:
究其原因是如果你的某段代码同一个线程中包含了不止一次的CRUD操作,在某一次的操作后,如果把session被关闭了,下一次操作检索到session被关闭了,就会出现上面的异常信息。
解决办法如下:
1.将这些CRUD操作放在一个session被关闭之前进行。
2.如果你的代码中使用了spring进行事务的管理,推荐使用getHibernateTemplate()的方式进行CRUD操作;避免在同一段代码中同时出现getHibernateTemplate()和getSession()两种方式进行CRUD操作。
欢迎关注我的微信公众号:JavaQ
java.lang.IllegalStateException: No value for key [org.hibernate.impl.SessionFactoryImpl@1b912ed] bound to thread
究其原因是如果你的某段代码同一个线程中包含了不止一次的CRUD操作,在某一次的操作后,如果把session被关闭了,下一次操作检索到session被关闭了,就会出现上面的异常信息。
解决办法如下:
1.将这些CRUD操作放在一个session被关闭之前进行。
2.如果你的代码中使用了spring进行事务的管理,推荐使用getHibernateTemplate()的方式进行CRUD操作;避免在同一段代码中同时出现getHibernateTemplate()和getSession()两种方式进行CRUD操作。
欢迎关注我的微信公众号:JavaQ
相关文章推荐
- No value for key [org.hibernate.impl.SessionFactoryImpl 异常解决
- No value for key SessionFactoryImpl
- No value for key [org.hibernate.impl.SessionFactoryImpl@1b912ed] bound to thread
- org.hibernate.HibernateException: No Session found for current thread的解决办法
- 【已解决】NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()...
- 关于异常: org.hibernate.HibernateException: No Session found for current thread
- 打开session的方法和org.hibernate.HibernateException: No CurrentSessionContext configured! 异常
- Spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法 转载的
- SpringMVC3+Hibernate4问题:org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernat
- spring hiberante 集成出现异常 java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor
- 异常处理:No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer...org
- org.hibernate.HibernateException: No Session found for current thread
- Git 解决同步 No value for key branch.master.merge found in
- Spring3与hibernate4整合,sessionFactory.getCurrentSession()方法获取不到Session对象异常解决办法
- Spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法 转载的
- SSH项目常见异常处理之[org.hibernate.LazyInitializationException: could not initialize proxy - no Session]
- org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 解决方法
- java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.springfram