我的應用程序中有一個奇怪的現象。爲什麼第一個(也是唯一的第一個!)訪問Spring Data存儲庫查找程序總是回滾我的EJB事務?
我是本地無狀態EJB裏面,想調用另一個本地無狀態EJB,這會導致以下異常:
javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted
雖然我研究我發現了問題,通常這種情況的原因在嘗試調用第二個(內部)EJB之前,它是第一個EJB內部代碼中某處的運行時異常。
顯然即使當運行時異常獲取,並進行處理,它唯一的作用是作爲回滾到標記的事務。迄今爲止這麼容易理解。
事情是我不知道在相關的代碼中的任何運行時異常。但是,我能夠找到的導致該一行代碼,它是訪問Spring數據倉庫取景器,像這樣的:
@Inject
CompanyRepository companyRepo;
Company company = companyRepo.findByName(inputVO.getCompanyName());
我有幾個倉庫,它並不重要哪一個我電話,他們都造成這種影響。
但是,只有在重新部署應用程序之後的第一次調用期間。之後,一切正常,直到我重新部署應用程序或重新啓動Payara服務器。
噢,順便說一下,在調用取景器,方法總是以一個有效的結果,甚至在第一次通話沒有「看得見」異常返回。
我假設有是出動和處理,因此不給我看到了春天的數據代碼裏面的一些運行時異常。也許某種「惰性初始化」,其中的東西只有在異常表明它不在之前被初始化?我不知道......這只是一種預感。
無論如何,我很想知道是否有人知道如何解決這個問題? (做一個@PostConstruct內的虛擬呼叫取景器似乎有點「不優雅」)
或者,也許有人甚至知道這個來源和如何避免產品總數? (但請記住,我沒有在Spring容器中運行,我在Payara服務器中,我只使用Spring框架中的Spring數據庫) :
<?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>