Spring 当我的insert语句失败时,延迟加载没有会话异常
已经从jpa会话加载了一个实体,我将它放在一个ThreadLocal中 但是当在spring中mvc控制器出现异常时引起的Spring 当我的insert语句失败时,延迟加载没有会话异常,spring,hibernate,session,spring-mvc,Spring,Hibernate,Session,Spring Mvc,已经从jpa会话加载了一个实体,我将它放在一个ThreadLocal中 但是当在spring中mvc控制器出现异常时引起的 public class CustomSettingsFilter extends OncePerRequestFilter { } 我没有发现这个例外 然后它就被处理了 "org.hibernate.PropertyValueException: not-null property references a null or transient value: net.s
public class CustomSettingsFilter extends OncePerRequestFilter {
}
我没有发现这个例外
然后它就被处理了
"org.hibernate.PropertyValueException: not-null property references a null or transient value: net.shopxx.entity.Bom.member"
common.i18n.entity.Currency_$$\uJavassist_6“我在ThreadLocal中持有的这个对象 异常日志:
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="shop/common/error" />
<property name="warnLogCategory">
<value>
org.springframework.web.servlet.handler.SimpleMappingExceptionResolver
</value>
</property>
</bean>
Template processing error: "get(currencyDescriptions) failed on instance of common.i18n.entity.Currency_$$_javassist_6"
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
我做了以下几件事:
请帮助我。谢谢大家你能发布你的映射和一些代码吗?嗨,我在我的实体上使用了jpa注释。这个由not null属性引起的异常引用了一个null或瞬态值,因为我没有给这个属性赋值,然后导致了这个异常,现在,我关心的是,为什么?1.会话已关闭?这个异常可能有不同的类型原因,一些提示为什么?会话关闭了?正如我在文章中所描述的,当我故意注释被新的RuntimeException替换的perisit代码段时,目标实体延迟加载是正常的,或者我在perisit代码段周围进行了一次尝试捕获,这也是正常的,所以它只在我有任何操作时出现,只需处理spring mvc exceptionResolver,不正常现在!太混乱了。@Benoit Wickramarachi,在我的例子中,与您给定的链接有一些不同,我从来没有手动关闭会话,我希望应用程序异常可以由默认的spring异常解析程序在没有捕获任何异常的情况下通过会话关闭来捕获。如果只是从这个问题开始,我只给它一个值。
Template processing error: "get(currencyDescriptions) failed on instance of common.i18n.entity.Currency_$$_javassist_6"
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: net.shopxx.entity.Bom.member
at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:103)
at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:132)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:214)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:178)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:853)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:827)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:831)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
... 85 more
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47123 ] - [ DEBUG ] Returning cached instance of singleton bean 'freeMarkerConfigurer'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47124 ] - [ DEBUG ] Invoking afterPropertiesSet() on bean with name 'shop/common/error'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47127 ] - [ DEBUG ] Rendering view [org.springframework.web.servlet.view.freemarker.FreeMarkerView: name 'shop/common/error'; URL [shop/common/error.ftl]] in DispatcherServlet with name 'springmvc'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47128 ] - [ DEBUG ] Added model object 'springMacroRequestContext' of type [org.springframework.web.servlet.support.RequestContext] to request in view with name 'shop/common/error'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47128 ] - [ DEBUG ] Added model object 'exception' of type [javax.persistence.PersistenceException] to request in view with name 'shop/common/error'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47129 ] - [ DEBUG ] Rendering FreeMarker template [shop/common/error.ftl] in FreeMarkerView 'shop/common/error'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47130 ] - [ DEBUG ] No properties file found for [/WEB-INF/language/common/message_en_uk] - neither plain properties nor XML
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47130 ] - [ DEBUG ] Re-caching properties for filename [/WEB-INF/language/common/message_zh_CN] - file hasn't been modified
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47131 ] - [ DEBUG ] No properties file found for [/WEB-INF/language/common/message_zh] - neither plain properties nor XML
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47131 ] - [ DEBUG ] No properties file found for [/WEB-INF/language/common/message] - neither plain properties nor XML
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47132 ] - [ DEBUG ] No properties file found for [/WEB-INF/language/shop/message_en_uk] - neither plain properties nor XML
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47132 ] - [ DEBUG ] Re-caching properties for filename [/WEB-INF/language/shop/message_zh_CN] - file hasn't been modified
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47133 ] - [ DEBUG ] Returning cached instance of singleton bean 'transactionManager'
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47134 ] - [ DEBUG ] Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@73494c99] for JPA transaction
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47134 ] - [ DEBUG ] Creating new transaction with name [net.shopxx.service.impl.LocalInfoServiceImpl.findAll]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47135 ] - [ DEBUG ] begin
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47135 ] - [ DEBUG ] initial autocommit status: true
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47136 ] - [ DEBUG ] disabling autocommit
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47136 ] - [ DEBUG ] Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@2aa4071a]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47137 ] - [ DEBUG ] Rendered criteria query -> select generatedAlias0 from LocalInfo as generatedAlias0 order by generatedAlias0.order asc
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47138 ] - [ DEBUG ] select localinfo0_.id as id1_2_, localinfo0_.create_gmt as create2_2_, localinfo0_.is_deleted as is3_2_, localinfo0_.modify_gmt as modify4_2_, localinfo0_.orders as orders5_2_, localinfo0_.country as country6_2_, localinfo0_.currency as currenc18_2_, localinfo0_.decimal_format as decimal7_2_, localinfo0_.decimal_separator as decimal8_2_, localinfo0_.digit as digit9_2_, localinfo0_.grouping_separator as groupin10_2_, localinfo0_.icon as icon11_2_, localinfo0_.is_default as is12_2_, localinfo0_.is_enable as is13_2_, localinfo0_.lan as lan14_2_, localinfo0_.language as languag15_2_, localinfo0_.local_code as local16_2_, localinfo0_.short_country as short17_2_, localinfo0_.time_zone as time19_2_ from i18n_localinfo localinfo0_ order by localinfo0_.orders asc
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47139 ] - [ DEBUG ] Result set row: 0
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47140 ] - [ DEBUG ] Result row: EntityKey[common.i18n.entity.LocalInfo#1]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47141 ] - [ DEBUG ] Result set row: 1
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47141 ] - [ DEBUG ] Result row: EntityKey[common.i18n.entity.LocalInfo#2]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47142 ] - [ DEBUG ] Resolving associations for [common.i18n.entity.LocalInfo#1]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47142 ] - [ DEBUG ] Done materializing entity [common.i18n.entity.LocalInfo#1]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47143 ] - [ DEBUG ] Resolving associations for [common.i18n.entity.LocalInfo#2]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47143 ] - [ DEBUG ] Done materializing entity [common.i18n.entity.LocalInfo#2]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47144 ] - [ DEBUG ] Initiating transaction commit
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47144 ] - [ DEBUG ] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@73494c99]
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47145 ] - [ DEBUG ] committing
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47145 ] - [ DEBUG ] committed JDBC Connection
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47146 ] - [ DEBUG ] re-enabling autocommit
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47146 ] - [ DEBUG ] Not closing pre-bound JPA EntityManager after transaction
2013-07-23 15:59:28 [ http-apr-8080-exec-4:47148 ] - [ ERROR ] Template processing error: "get(currencyDescriptions) failed on instance of common.i18n.entity.Currency_$$_javassist_6"