私のアプリケーションには奇妙な現象があります。Spring Dataリポジトリファインダへの最初の(そして最初の!)アクセスは、常にEJBトランザクションをロールバックしますか?
私は地元のステートレスEJB内だと、次の例外が発生し、別のローカルステートレスEJBを、呼び出したい:
javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted
私が見つけた問題を調査している間、このため通常の理由第2の(内部の)EJBを呼び出す前に、最初のEJB内部のコードのどこかで実行時例外です。
ランタイム例外がキャッチされて処理されても、トランザクションをロールバックとしてマークするだけで十分です。これまでのところ理解できます。
問題は関連するコードのランタイム例外を認識していないことです。しかし、私はこれを原因となる単一のコード行を見つけることができましたし、それは春データリポジトリファインダーへのアクセスで、この1のように:
@Inject
CompanyRepository companyRepo;
Company company = companyRepo.findByName(inputVO.getCompanyName());
私はいくつかのリポジトリを持っており、それが1つの私の問題ではありません。これらすべてがこの効果を引き起こします。
ただし、アプリケーションの再デプロイ後の最初の呼び出し中にのみ発生します。その後、アプリケーションを再デプロイするか、Payaraサーバーを再起動するまで、すべて正常に動作します。
ああ、ところで、ファインダーメソッドの呼び出しは常に有効な結果を返し、最初の呼び出しでも "可視"例外は返されません。
私は、アタッチされて処理され、したがって私には見えないSpringデータコード内にある実行時例外があると仮定します。たぶん、ある種の「怠惰な初期化」は、例外がそれが以前ではなかったことを物語が初期化しただけであるということを示していますか?私は知らない...それはちょうど馬鹿です。
とにかく、誰かがこれを回避する方法を知っていたら、私は興味がありましたか? (@PostConstructの中でダミーのファインダコールを行うのはちょっと「エレガントではない」と思われます)
誰かがこれのソースとそれを避ける方法を知っているかもしれませんか?
私は下記のapplicationContext.xmlを含めることにします(ただし、私はSpringコンテナでは実行していないことを心に留めておきますが、私はPayaraサーバーにいます。 :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<jpa:repositories base-package="de.otto.cccs.customerscoring.entities" />
<tx:jta-transaction-manager />
<tx:annotation-driven />
<context:component-scan base-package="de.otto.cccs" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/COR99TSDatasource" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="default" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform"
value="org.eclipse.persistence.platform.database.OraclePlatform" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
</beans>