0
<filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>
         org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
    </filter-class>
</filter>
<filter-mapping>
   <filter-name>openSessionInViewFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

これは webx.xml フィルター設定です

そして私のカスタムフィルターで:

public class CustomSettingsFilter extends OncePerRequestFilter {

}

jpaセッションからエンティティをロードし、それを ThreadLocal に入れました。

しかし、春のmvcコントローラーで例外が発生した場合

"org.hibernate.PropertyValueException: not-null property references a null or transient value: net.shopxx.entity.Bom.member"  

そして、私はこの例外をキャッチしませんでした。

次に、それは

 <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

common.i18n.entity.Currency_$$_javassist_6" ThreadLocal に保持するこのオブジェクト

例外のログ:

    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"

そして私は以下のことをします:

  1. 例外コードをコメントし、コントローラーで実行時例外をスローすると、セッションなしの例外は表示されませんでした。
  2. try catch でjpa例外をキャッチし、セッション例外も表示されなかった場合

助けてください。どうもありがとう

4

0 に答える 0