No value for key [org.hibernate.impl.SessionFactoryImpl 异常解决

使用Hibernate+Spring进行CRUD操作时,出现如下类似异常信息:

java.lang.IllegalStateException: No value for key [[email protected]] bound to thread 

究其原因是如果你的某段代码同一个线程中包含了不止一次的CRUD操作,在某一次的操作后,如果把session被关闭了,下一次操作检索到session被关闭了,就会出现上面的异常信息。

解决办法如下:

1.将这些CRUD操作放在一个session被关闭之前进行。

2.如果你的代码中使用了spring进行事务的管理,推荐使用getHibernateTemplate()的方式进行CRUD操作;避免在同一段代码中同时出现getHibernateTemplate()和getSession()两种方式进行CRUD操作。

No value for key [org.hibernate.impl.SessionFactoryImpl 异常解决

时间: 2024-08-30 17:15:20

No value for key [org.hibernate.impl.SessionFactoryImpl 异常解决的相关文章

hibernate开发错误及解决办法

1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at net.sf.hibernate.cfg.Configuration.(Configuration.java:95) at cn.yuan.xmlparse.base._BaseRootDAO.initialize(_BaseRootDAO.java:49) at cn.yuan.x

hibernate Unknown entity异常解决方案

org.hibernate.MappingException: Unknown entity异常详细信息如下: org.hibernate.MappingException: Unknown entity: com.gis520.model.Emp_emp at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628) at org.hibernate.impl.SessionImp

Spring + SpringMVC + Druid + JPA(Hibernate impl) 给你一个稳妥的后端解决方案

最近手头的工作不太繁重,自己试着倒腾了一套用开源框架组建的 JavaWeb 后端解决方案. 感觉还不错的样子,但实践和项目实战还是有很大的落差,这里只做抛砖引玉之用. 项目 git 地址:https://git.oschina.net/LanboEx/sdh.git 大体采用的开源项目有:Spring + SpringMVC + Druid + JPA(Hibernate Impl). 1. 采用到的开源项目漫谈 Spring 迷人的依赖注入特性, 使其已经稳稳的占据在 JavaEE 项目引用开

Caused by: java.lang.ClassNotFoundException: org.hibernate.impl.SessionImpl

1.错误描述 2015-09-20 23:02:58 [main] WARN org.springframework.context.support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error cre

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法 为什么还会说已经存在相同的session了呢.然后每次将项目重启后第一次编辑的时候问题不会触发,只有当第二次操作的时候才会出现这个问题. 解决办法:关闭session.好好检查操作完成后有没有关闭会话. org.hibernat

Hibernate整合Spring异常'sessionFactory' or 'hibernateTemplate' is required

今日在写GenericDao时,发现了一个异常,内容如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao' defined in class path resource [spring.common.xml]: Invocation of init method failed; nested exception is java.lang.Ille

ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决

ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决 根据异常提示:我找了我的MySQL语句:果然找到了 将FORM修改为FROM后运行就对了 这些都是粗心导致,希望我能记住这个错误. 我百度了一下,发现还有许多类似的错误 总结: ERROR org.hibernate.hql.internal.ast.ErrorCounter :unexpected token: xxxx 解决办法: 1.首

JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

测试又报bug啦 接到测试小伙伴的问题,说是一个接口不返回数据了,好吧,虽然不是我写的接口任务落到头上也得解决,本地调试了一下,好家伙,直接抛了个异常出来,这又是哪位大哥喝醉了写的代码... Exception in thread "main" java.lang.IllegalStateException: Duplicate key at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)

org.hibernate.id.IdentifierGenerationException错误解决方法

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ID主键生成策略为assigned 由应用程序负责生成主键标识符 <id name="id" type="java.lang.String"> <column name="ID" length=&qu