我有一個與Spring設置的Web應用程序來創建我的休眠會話工廠(單身人士)和會議和事務(都是請求作用域),但它正在銷燬會話並以錯誤的順序進行交易。我如何配置它,以便在會話之前銷燬事務?這是我的春天applicationContext.xml文件:試圖以正確的順序銷燬豆與春
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="hibernateSessionFactory" scope="singleton"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<!-- The per-http request hibernate session -->
<bean id="hibernateSession" factory-bean="hibernateSessionFactory"
factory-method="openSession" destroy-method="close" scope="request" />
<!-- The per-http request transaction (i need this to be destroyed BEFORE the session) -->
<bean id="hibernateTransaction" factory-bean="hibernateSession"
factory-method="beginTransaction" destroy-method="commit" scope="request" />
</beans>
而這裏的,顯示它在會議閉幕它關閉前交易日誌:
16111 [http-8080-3] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'hibernateSession'
16111 [http-8080-3] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
16111 [http-8080-3] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - trace [email protected] [managed: 4, unused: 3, excluded: 0] (e.g. [email protected])
16111 [http-8080-3] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'commit' on bean with name 'hibernateTransaction'
16111 [http-8080-3] DEBUG org.hibernate.transaction.JDBCTransaction - commit
16111 [http-8080-3] WARN org.springframework.beans.factory.support.DisposableBeanAdapter - Invocation of destroy method 'commit' failed on bean with name 'hibernateTransaction'
org.hibernate.SessionException: Session is closed
嗨, 我有一個懷疑,春天有內置的選項管理會議/ txn,但是在閱讀這兩個鏈接後,我仍然沒有接近理解他們的工作方式。我想我會選擇你的'助手班'選項,這是一個好主意。我覺得春天無法控制摧毀秩序是一件可惜的事情,但對我來說這並不是那麼重要。 – Chris 2010-01-18 02:02:10
我看了看那兩個鏈接,我看不到我怎麼可以使用spring事務管理器(或其他任何東西)給我一個會話和事務,我可以注入到我的動作中,它似乎只給我一個會話工廠,然後我可以調用'getCurrentSession()',這對我來說看起來不太好。 – Chris 2010-01-18 02:03:57
我猜我在問什麼,如果這不是最好的方式,那麼*是用spring來管理session/txns的最好方法? – Chris 2010-01-18 02:10:00