1

JTA トランザクションで動作するように Spring アプリケーションを構成しようとしています。失敗しているわけではありませんが、試したことはすべて選択を行うだけで、永続化操作は無視されます。

次のログでわかるように、save ステートメントが実行されても、insert ステートメントはなく、例外もエラー/警告ログもありません。

サーバーログ

DEBUG [xxxx.xxxx.persistence] (http--0.0.0.0-8080-1) execute $Proxy363.save(whatever.core.entities.XxxAssignedTime@51a8c542)
DEBUG [org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource] (http--0.0.0.0-8080-1) Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (http--0.0.0.0-8080-1) Returning cached instance of singleton bean 'transactionManager'
DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--0.0.0.0-8080-1) Participating in existing transaction
INFO  [xxxx.xxxx.impl.BpmnUserBusinessImpl] (http--0.0.0.0-8080-1) Last Assigned Time Updated to *******, Thu Sep 06 15:48:48 ICT 2012

これは、アプリケーション サーバーがすべてがうまくいったと考えているようなものです。テーブルをチェックすると、挿入も更新も行われませんでした。

Spring アプリケーションで使用する予定のデータソースは、同じアプリケーション サーバーで実行されている Java EE war アプリケーションによって JTA トランザクションで正常に使用されます。

どこに問題があるのか​​ わからないので、すべてを完全な文脈で説明したいと思います.

  • 春 3.1.2-RELEASE
  • 休止状態 4.1.5.Final
  • spring-data-jpa 1.1.1.Final
  • アパッチ軸1.4
  • jbos AS7.1
  • DB: オラクル 10g

私たちはそれを機能させるためにあらゆる種類のクレイジーな構成を試してきたので、ここでは最も単純なものをコピーします.

スタンドアロン.xml

<datasource jta="true" jndi-name="java:jboss/datasources/EngineDS" pool-name="EngineDS" enabled="true" use-java-context="true" use-ccm="true">
    <connection-url>jdbc:oracle:thin:@server:port:****</connection-url>
    <driver>oracle</driver>
    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>100</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>****</user-name>
        <password>****</password>
    </security>
    <statement>
        <prepared-statement-cache-size>32</prepared-statement-cache-size>
        <share-prepared-statements>true</share-prepared-statements>
    </statement>
</datasource>
<drivers>
    <driver name="oracle" module="com.oracle.ojdbc6">
        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    </driver>
</drivers>

web.xml

[...]
<resource-ref id="DS">
 <res-ref-name>EngineDS</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
 <res-sharing-scope>Shareable</res-sharing-scope>
 <mapped-name>java:jboss/datasources/EngineDS</mapped-name>
</resource-ref>
[...]

spring-jpa-config.xml

<jpa:repositories base-package="whatever.core.repositories" />
<jee:jndi-lookup id="dataSource" jndi-name="EngineDS" cache="true" resource-ref="true" expected-type="javax.sql.DataSource"/>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="whatever.core.entities" />
<property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="${hibernate.show_sql}" />
    <property name="generateDdl" value="${jpa.generateDdl}" />
    <property name="databasePlatform" value="${jpa.dialect}" />
    </bean>
    </property>
 </bean>

 <tx:annotation-driven />
 <tx:jta-transaction-manager />

 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
 <bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>

私たちは過去に jboss AS5/Spring 3.0 アプリケーションを作成して JTA トランザクションを操作していたので、これが初めてというわけではありません。見つけられるすべての可能なブログとオープン ソース プロジェクトを調べてきました。しかし、誰にとってもスムーズに機能するように見えるものはすべて、私のアプリケーションでは無視されているようです。本当にばかげた何かがどこかに欠けているはずですが、これまでに70以上の異なる構成を試しましたが、JTAを試していないときに機能する単純な挿入を行うものはありません。

(軸 1.4 を使用するという事実は、関連するかどうかはわかりませんが、私たちのアプリケーションは Web サービスの呼び出し後にのみアクションをトリガーするため、お伝えしたいと思います)。この時点で、私たちは構成の超常現象を信じ始めています...

手がかりはありますか?

4

1 に答える 1

2

を使用していたため、上記の構成が機能していないことが判明しましたorg.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean

JTA を使用するには、JBoss コンテナー管理のエンティティ マネージャーを検索する必要がありますspring-jpa.config.xml

<!-- lookup the container-managed JPA-EMF --> 
<!-- the JNDI name is specified in META-INF/persistence.xml --> 
<!-- SEE: https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-BindingEntityManagerFactorytoJNDI --> 
<jee:jndi-lookup id="defaultPu" jndi-name="java:jboss/defaultPu" />

そしてMETA-INF/persistence.xml、Entity Manager Factory を JNDI にバインドします。

<!-- bind the EMF in JNDI --> 
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/defaultPu" /> 

そこで、Jboss に JPA をブートストラップさせ、そのようにして JTA トランザクションが機能するようにしました。

于 2012-10-29T02:09:14.607 に答える