我是JTA的新手,我想在我的應用程序中執行兩個階段的提交,它將連接到兩個不同的數據庫模式。 我在我的應用程序中使用Spring,Hibernate和JPA,我想添加JTA事務管理器,但是我還沒有能夠通過這個。沒有交易正在進行中JTA交易
有人可以幫助我解決我面臨的問題,或者指出我的配置或理解有什麼問題。
這是我在配置設置文件
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="LineManagement" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="false" />
<property name="databasePlatform" value="${hibernate.dialect}" />
</bean>
</property>
<property name="beanName" value="entityManager"></property>
</bean>
<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp"
init-method="init" depends-on="setAtomikosSystemProps">
<constructor-arg>
<props>
<prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
</props>
</constructor-arg>
</bean>
<bean id="setAtomikosSystemProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperties" />
</bean>
</property>
<property name="targetMethod" value="putAll" />
<property name="arguments">
<util:properties>
<prop key="com.atomikos.icatch.file">/jta.properties</prop>
<prop key="com.atomikos.icatch.hide_init_file_path">true</prop>
<prop key="com.atomikos.icatch.console_log_level">DEBUG</prop>
</util:properties>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" >
<property name="userTransaction" ref="AtomikosUserTransaction" />
<property name="transactionManager" ref="AtomikosTransactionManager" />
</bean>
<bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService" >
<property name="transactionTimeout" value="300"/>
</bean>
<bean id="AtomikosTransactionManager" class = "com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
persistence.xml中具有以下配置
<persistence-unit name="LineManagement" transaction-type="JTA">
<properties>
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.current_session_context_class" value="thread" />
<property name="hibernate.default_batch_fetch_size" value="200" />
<property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
<property key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<!-- General Debugging -->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.generate_statistics" value="true" />
</properties>
</persistence-unit>
當我運行應用程序時,它給了我一個異常 org.springframework。 dao.InvalidDataAccessApiUsageException:沒有事務正在進行;嵌套的例外是javax.persistence.TransactionRequiredException:沒有交易正在進行
我試圖淤泥與周圍的@Transactional註解的傳播史的標誌,因爲我相信這個例外規定,心不是禮物的交易,但它沒有做錯誤消失...
也許' '會有幫助嗎? –
2012-02-16 18:23:56
我在我的配置中有這個。我指的是稍後指定的transactionManger –
Hrishikesh
2012-02-16 18:37:06
在JBoss上,我設法得到一個類似的配置才能在刪除之後工作: org.hibernate.transaction.JTATransactionFactory 在此之前,所有工作(包括2階段提交)除了entitymanager持久/合併/刪除方法。爲什麼?我不知道 :( –
Vedran
2012-10-03 07:38:26