如何连接org.springframework.transaction.interceptor.TransactionProxyFactoryBean和org.springframework.orm.hibernate3.HibernateInterceptor?
我接通了电源,但没有按我预期的那样工作。 我已经将实体之间的惰性初始化设置为true,相信HibernateInterceptor管理hibernate会话。当我试图访问对象属性时,它会引发异常LazyInitializationException如何连接org.springframework.transaction.interceptor.TransactionProxyFactoryBean和org.springframework.orm.hibernate3.HibernateInterceptor?,hibernate,spring,Hibernate,Spring,我接通了电源,但没有按我预期的那样工作。 我已经将实体之间的惰性初始化设置为true,相信HibernateInterceptor管理hibernate会话。当我试图访问对象属性时,它会引发异常LazyInitializationException Error messgae : Transaction could not initialize proxy - the owning Session was closed Stack Trace: org.hibernate.LazyInitia
Error messgae : Transaction could not initialize proxy - the owning Session was closed
Stack Trace: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
配置xml
<!-- THE HIBERNATE INTERCEPTOR -->
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory" ref="app:sessionFactory" />
</bean>
<!-- Start Transaction proxy definition -->
<bean id="app:appTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="app:transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="process*">PROPAGATION_REQUIRED,readOnly,
-Exception,-RuntimeException</prop>
<prop key="submit*">PROPAGATION_REQUIRED,readOnly,
-Exception,-RuntimeException</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly,
-Exception,-RuntimeException</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<ref bean="hibernateInterceptor" />
</list>
</property>
<property name="postInterceptors">
<list>
<ref bean="hibernateInterceptor" />
</list>
</property>
</bean>
<bean id="app:daoTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="app:transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="unlock*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="getHead*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="remove*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="create*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="update*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="addTail*">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="checkForTimeouts">PROPAGATION_REQUIRED,
-Exception,-RuntimeException</prop>
<prop key="breakOldLocks">PROPAGATION_REQUIRES_NEW,
-Exception,-RuntimeException</prop>
<prop key="find*">PROPAGATION_REQUIRES_NEW,readOnly,
-Exception,-RuntimeException</prop>
<prop key="load*">PROPAGATION_REQUIRES_NEW,readOnly,
-Exception,-RuntimeException</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly,
-Exception,-RuntimeException</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<ref bean="hibernateInterceptor" />
</list>
</property>
<property name="postInterceptors">
<list>
<ref bean="hibernateInterceptor" />
</list>
</property>
</bean>
<bean id="app:transactionManager" name="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="app:sessionFactory" />
<property name="nestedTransactionAllowed" value="true" />
</bean>
<bean id="app:sessionFactory" name="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="app:dataSource" />
<property name="mappingResources">
<list>
<value>com/app/domain/app.hbm.xml</value>
<value>com/common/domain/shared.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${app.hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.generate_statistics">false</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
</bean>
<!--Start DATA SOURCE -->
<bean id="app:dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!-- Config values-->
</bean>
需要传播,只读,
-异常,-运行时异常
需要传播,只读,
-异常,-运行时异常
需要传播,只读,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
如有需要,
-异常,-运行时异常
传播需要新的,
-异常,-运行时异常
传播需要新的、只读的,
-异常,-运行时异常
传播需要新的、只读的,
-异常,-运行时异常
需要传播,只读,
-异常,-运行时异常
com/app/domain/app.hbm.xml
com/common/domain/shared.hbm.xml
${app.hibernate.dial}
假的
假的
这个?ProxyFactoryBean上的任何输入都允许对bean方法调用应用特定的逻辑。TransactionProxyFactoryBean是一个ProxyFactoryBean,它允许应用特定于事务管理的关注点
LazyInitializationException意味着您在活动hibernate会话上下文之外访问hibernate代理
也就是说,您设置了事务基础设施,要求hibernate为特定实体获取代理,并在事务完成后尝试访问代理属性
解决方案是急切地检索对象或仅从事务上下文使用对象。您的“应用程序:transactionManager”在哪里?是的,我添加了“app:transactionManager”,您是对的,但我使用org.springframework.orm.hibernate3.HibernateInterceptor作为前侦听器和后侦听器,它应该在方法调用之前将新的Hibernate会话绑定到线程,然后在出现任何方法结果时关闭并删除它。如果已经有一个预绑定会话,拦截器只会参与其中。()这里有什么错误吗?好的,那么您可以通过hibernate检索一个实体并设置HibernateInterceptor以应用于该实体,或者HibernateInterceptor的目标是什么?TransactionProxyFactoryBean是FactoryBean,而不是ProxyFactoryBean。