Transaction not active JTA spring data jpa and hibernate4
fduartej Mar 25, 2013 4:25 PMHi Everybody:
I want to set up spring-data-jpa-1.1.0, spring-3.1.2 and hibernate-4.1.1 on jboss 7.1 but I have a lot of problem with that I have been trying to make the right setting but I cant find what is the best because when I have tried to use JTA doing transaction in two databases but always show me transaction is not active, why happend this????
This is spring setting
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:jboss/TransactionManager" /> <property name="userTransactionName" value="java:jboss/UserTransaction" /> </bean> <tx:annotation-driven transaction-manager="txManager" /> <jpa:repositories base-package="com.axcessfinancial.poc.performance.repository" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="txManager" /> <jpa:repositories base-package="com.axcessfinancial.poc.performance2.repository" entity-manager-factory-ref="entityManagerFactory2" transaction-manager-ref="txManager" /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> </property> <property name="packagesToScan" value="com.axcessfinancial.poc.performance.domain"/> <property name="persistenceUnitName" value="domain-jpa"></property> <property name="jpaProperties"> <props> <prop key="hibernate.transaction.factory_class"> org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory </prop> <prop key="hibernate.transaction.jta.platform"> org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform </prop> <prop key="current_session_context_class">jta</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">10</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="entityManagerFactory2" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource2" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> </property> <property name="packagesToScan" value="com.axcessfinancial.poc.performance.domain2"/> <property name="persistenceUnitName" value="domain-jpa2"></property> <property name="jpaProperties"> <props> <prop key="hibernate.transaction.factory_class"> org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory </prop> <prop key="hibernate.transaction.jta.platform"> org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform </prop> <prop key="current_session_context_class">jta</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">10</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
This is a transactional annotations
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = { Exception.class }) public Long createCustomer() { entity1db1() entity2db2()
This is the error log
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Transaction not active; nested exception is java.lang.IllegalStateException: Transaction not active at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:298) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:106) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.convertException(ExtendedEntityManagerCreator.java:501) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.afterCommit(ExtendedEntityManagerCreator.java:481) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCommit(TransactionSynchronizationUtils.java:133) [spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerAfterCommit(TransactionSynchronizationUtils.java:121) [spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
Thanks
Fred