我最近开始使用 JBossTM 以便在多个数据库连接上使用 JTA,这非常成功。如果我尝试从任何控制器执行事务,它可以正常工作。
但是,我最近开始尝试从 HttpSessionListener 的实例中持久化实体,以便我可以跟踪用户会话,但我无法让持久化工作。我敢肯定,我在这里缺少一些非常简单的东西,但任何提示都会受到欢迎。
问题是,尽管一切似乎都运行正常(日志方面),但实际上没有任何东西被提交到数据库中。在尝试持久保存到没有事务管理器的数据库之前(在我切换到 JBossTM 之前),我已经看到了这个错误,但似乎无法破解它。
以下是我的 application-context.xml 的相关位:
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="com.arjuna.ats.jta.TransactionManager" factory-method="transactionManager" id="arjunaTransactionManager"/>
<bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction" id="arjunaUserTransaction"/>
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager">
<ref bean="arjunaTransactionManager"/>
</property>
<property name="userTransaction">
<ref bean="arjunaUserTransaction"/>
</property>
</bean>
<jee:jndi-lookup id="CoreDS" jndi-name="java:/comp/env/jdbc/CoreDS" resource-ref="true" />
<bean id="coreEMW" class="org.springframework.orm.jpa.support.SharedEntityManagerBean"
p:entityManagerFactory-ref="coreEMF"/>
<bean id="coreEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="CoreDS"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="sessionDAO" class="core.dao.SessionDAOImpl"
p:entityManager-ref="coreEMW" />
<bean name="openEntityManagerInViewInterceptor"
class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor"
p:entityManagerFactory-ref="coreEMF" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id='jdbcTemplate' class='org.springframework.jdbc.core.JdbcTemplate'
p:dataSource-ref='CoreDS' />
web.xml
<listener>
<listener-class>core.util.SessionListener</listener-class>
</listener>
会话监听器.java
public class SessionListener implements HttpSessionListener {
private static Log log = LogFactory.getLog(SessionListener.class);
@Override
@Transactional
public void sessionCreated(HttpSessionEvent event) {
getDAO(event).save(new Session(event.getSession().getId(),Calendar.getInstance()));
}
@Override
public void sessionDestroyed(HttpSessionEvent event) {
....
}
private SessionDAO getDAO(HttpSessionEvent event){
HttpSession session = event.getSession();
ApplicationContext ctx =
WebApplicationContextUtils.
getWebApplicationContext(session.getServletContext());
SessionDAO dao =
(SessionDAO) ctx.getBean("sessionDAO");
return dao;
}
}
持久性.xml
<persistence version="1.0" xmlns="...">
<persistence-unit name="BPSCorePU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:comp/env/jdbc/BPSCoreDS</non-jta-data-source>
...
<class>core.model.Session</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
日志(虽然您可以看到提交,但 Session 对象未持久化)
2013-04-18 15:47:41,763 [core.util.SessionListener] TRACE - sessionCreated(): C5A37E5CC12FF19C277769DA8B97BF0A
2013-04-18 15:47:41,798 [com.arjuna.ats.jta] TRACE - BaseTransaction.getStatus
2013-04-18 15:47:41,854 [com.arjuna.ats.arjuna] TRACE - Loading class com.arjuna.ats.internal.arjuna.coordinator.CheckedActionFactoryImple
2013-04-18 15:47:41,873 [com.arjuna.ats.jta] TRACE - BaseTransaction.begin
2013-04-18 15:47:41,882 [com.arjuna.ats.arjuna] TRACE - Loading class com.arjuna.ats.arjuna.recovery.ActionStatusService
2013-04-18 15:47:41,889 [com.arjuna.ats.arjuna] TRACE - Loading class com.arjuna.ats.internal.arjuna.objectstore.ShadowNoFileLockStore
2013-04-18 15:47:41,891 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.createHierarchy(/tmp/jbosstm/tx/a/ShadowNoFileLockStore/defaultStore/)
2013-04-18 15:47:41,900 [com.arjuna.ats.arjuna] INFO - ARJUNA012163: Starting service com.arjuna.ats.arjuna.recovery.ActionStatusService on port 32882
2013-04-18 15:47:41,910 [com.arjuna.ats.arjuna] TRACE - Loading class com.arjuna.ats.internal.arjuna.utils.SocketProcessId
2013-04-18 15:47:41,912 [com.arjuna.ats.arjuna] INFO - ARJUNA012337: TransactionStatusManagerItem host: 127.0.0.1 port: 32882
2013-04-18 15:47:41,913 [com.arjuna.ats.arjuna] TRACE - OutputObjectState::OutputObjectState()
2013-04-18 15:47:41,914 [com.arjuna.ats.arjuna] TRACE - Loading class com.arjuna.ats.internal.arjuna.objectstore.ShadowNoFileLockStore
2013-04-18 15:47:41,914 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.createHierarchy(/tmp/jbosstm/tx/a/ShadowNoFileLockStore/defaultStore/)
2013-04-18 15:47:41,915 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.write_committed(0:ffffc0a80036:8073:5170078d:0, /Recovery/TransactionStatusManager)
2013-04-18 15:47:41,916 [com.arjuna.ats.arjuna] TRACE - ShadowingStore.write_state(0:ffffc0a80036:8073:5170078d:0, /Recovery/TransactionStatusManager, StateType.OS_ORIGINAL)
2013-04-18 15:47:41,916 [com.arjuna.ats.arjuna] TRACE - ShadowingStore.genPathName(0:ffffc0a80036:8073:5170078d:0, /Recovery/TransactionStatusManager, StateType.OS_ORIGINAL)
2013-04-18 15:47:41,916 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.genPathName(0:ffffc0a80036:8073:5170078d:0, /Recovery/TransactionStatusManager, 11)
2013-04-18 15:47:41,918 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.openAndLock(/tmp/jbosstm/tx/a/ShadowNoFileLockStore/defaultStore/Recovery/TransactionStatusManager/0_ffffc0a80036_8073_5170078d_0, FileLock.F_WRLCK, true)
2013-04-18 15:47:41,918 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.createHierarchy(/tmp/jbosstm/tx/a/ShadowNoFileLockStore/defaultStore/Recovery/TransactionStatusManager/0_ffffc0a80036_8073_5170078d_0)
2013-04-18 15:47:41,927 [com.arjuna.ats.arjuna] TRACE - FileSystemStore.closeAndUnlock(/tmp/jbosstm/tx/a/ShadowNoFileLockStore/defaultStore/Recovery/TransactionStatusManager/0_ffffc0a80036_8073_5170078d_0, null, java.io.FileOutputStream@283a0f10)
2013-04-18 15:47:41,927 [com.arjuna.ats.arjuna] INFO - ARJUNA012170: TransactionStatusManager started on port 32882 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
2013-04-18 15:47:41,928 [com.arjuna.ats.arjuna] TRACE - StateManager::StateManager( 2, 0 )
2013-04-18 15:47:41,928 [com.arjuna.ats.arjuna] TRACE - BasicAction::BasicAction()
2013-04-18 15:47:41,929 [com.arjuna.ats.arjuna] TRACE - BasicAction::Begin() for action-id 0:ffffc0a80036:8073:5170078d:2
2013-04-18 15:47:41,929 [com.arjuna.ats.arjuna] TRACE - BasicAction::actionInitialise() for action-id 0:ffffc0a80036:8073:5170078d:2
2013-04-18 15:47:41,930 [com.arjuna.ats.arjuna] TRACE - ActionHierarchy::ActionHierarchy(1)
2013-04-18 15:47:41,931 [com.arjuna.ats.arjuna] TRACE - ActionHierarchy::add(0:ffffc0a80036:8073:5170078d:2, 1)
2013-04-18 15:47:41,934 [com.arjuna.ats.arjuna] TRACE - BasicAction::addChildThread () action 0:ffffc0a80036:8073:5170078d:2 adding Thread["ajp-bio-8010"-exec-1,5,main]
2013-04-18 15:47:41,935 [com.arjuna.ats.arjuna] TRACE - BasicAction::addChildThread () action 0:ffffc0a80036:8073:5170078d:2 adding Thread["ajp-bio-8010"-exec-1,5,main] result = true
2013-04-18 15:47:41,938 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::instantiate()
2013-04-18 15:47:41,939 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::TransactionReaper ( 9223372036854775807 )
2013-04-18 15:47:41,941 [com.arjuna.ats.arjuna] TRACE - ReaperThread.run ()
2013-04-18 15:47:41,942 [com.arjuna.ats.arjuna] TRACE - Thread Thread[Transaction Reaper,5,main] sleeping for 9223370670558313865
2013-04-18 15:47:41,942 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::insert ( BasicAction: 0:ffffc0a80036:8073:5170078d:2 status: ActionStatus.RUNNING, 60 )
2013-04-18 15:47:41,944 [com.arjuna.ats.arjuna] TRACE - ReaperElement::ReaperElement ( BasicAction: 0:ffffc0a80036:8073:5170078d:2 status: ActionStatus.RUNNING, 60 )
2013-04-18 15:47:41,944 [com.arjuna.ats.arjuna] TRACE - ReaperThread.run ()
2013-04-18 15:47:41,944 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::check ()
2013-04-18 15:47:41,944 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::check - comparing 1366296521944
2013-04-18 15:47:41,945 [com.arjuna.ats.arjuna] TRACE - Thread Thread[Transaction Reaper,5,main] sleeping for 59999
2013-04-18 15:47:41,946 [com.arjuna.ats.arjuna] TRACE - ReaperWorkerThread.run ()
2013-04-18 15:47:41,946 [com.arjuna.ats.arjuna] TRACE - Thread Thread[Transaction Reaper Worker 0,5,main] waiting for cancelled TXs
2013-04-18 15:47:42,091 [dao.BaseDAOImpl] TRACE - Persisting
2013-04-18 15:47:42,091 [dao.BaseDAOImpl] DEBUG - adtest Shared EntityManager proxy for target factory [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@1dcd8d1f]
2013-04-18 15:47:42,091 [dao.BaseDAOImpl] DEBUG - adtest core.model.Session@6229abca
2013-04-18 15:47:42,120 [com.arjuna.ats.jta] TRACE - BaseTransaction.getStatus
2013-04-18 15:47:42,120 [com.arjuna.ats.jta] TRACE - TransactionImple.getStatus
2013-04-18 15:47:42,121 [com.arjuna.ats.jta] TRACE - BaseTransaction.getStatus
2013-04-18 15:47:42,121 [com.arjuna.ats.jta] TRACE - TransactionImple.getStatus
2013-04-18 15:47:42,121 [com.arjuna.ats.jta] TRACE - BaseTransaction.commit
2013-04-18 15:47:42,121 [com.arjuna.ats.jta] TRACE - TransactionImple.commitAndDisassociate
2013-04-18 15:47:42,121 [com.arjuna.ats.arjuna] TRACE - BasicAction::End() for action-id 0:ffffc0a80036:8073:5170078d:2
2013-04-18 15:47:42,122 [com.arjuna.ats.arjuna] TRACE - BasicAction::removeChildThread () action 0:ffffc0a80036:8073:5170078d:2 removing TSThread:1
2013-04-18 15:47:42,122 [com.arjuna.ats.arjuna] TRACE - BasicAction::removeChildThread () action 0:ffffc0a80036:8073:5170078d:2 removing TSThread:1 result = true
2013-04-18 15:47:42,122 [com.arjuna.ats.arjuna] TRACE - TransactionReaper::remove ( BasicAction: 0:ffffc0a80036:8073:5170078d:2 status: ActionStatus.COMMITTED )
所有已编辑以删除客户详细信息,因此可能存在一些错误
任何帮助将不胜感激!