1

最近、複数のデータベース接続で JTA を使用するために JBossTM を使い始めましたが、これは非常にうまくいきました。任意のコントローラーからトランザクションを実行しようとすると、問題なく動作します。

しかし、私は最近、ユーザー セッションを追跡できるように 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>

SessionListener.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;
    }
}

persistence.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 )

クライアントの詳細を削除するためにすべて編集されているため、いくつかの間違いがある可能性があります

どんな助けでも大歓迎です!

4

1 に答える 1