View Full Version : How do Spring JPA use JOTM(JTA) transaction??
zjnbshifox
Mar 16th, 2006, 04:59 AM
I use Spring 2.0M3,now can use hibernate entitymanager.
But I maybe need use JTA in the future, is there any suggestions?
my app server is TOMCAT 5.5.x
trisberg
Mar 16th, 2006, 11:17 AM
Spring does not really get involved here - you would just configure the persistence provider (Hibernate's JPA implementation is this case) to use the JTA DataSource rather than a Non-JTA Resource-local one. And you would use the JtaTransactionManager if you use Spring managed transactions.
zjnbshifox
Mar 16th, 2006, 11:01 PM
If I want to use an transaction with jpa & jms ,the following config have any problems? I have not try it out yet
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBea n"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFact oryBean">
<property name="entityManagerName" value="TestEntityManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager" ref="jotm" />
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.Annotat ionTransactionAttributeSource" />
</property>
</bean>
// here have some other config for annotation transaction....
<bean id="JTAtransactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager">
<property name="userTransaction">
<ref bean="jotm"/>
</property>
</bean>
<bean id="connectionFactory" class="com.marathon.jms.PooledSpringXAConnectionFactory">
<property name="connectionFactory">
<bean class="org.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
</property>
<property name="transactionManager" ref="jotm"/>
</bean>
<bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<bean id="destination" class="org.activemq.message.ActiveMQTopic" autowire="constructor">
<constructor-arg>
<value>Hello1.Topic</value>
</constructor-arg>
</bean>
anibal
Jul 24th, 2006, 11:28 AM
I'm also trying to use a transaction with jpa & jms and I'm wondering whether the JPATransactionActionManager will join the transactions from the JTATransactionManager.
Normally I would expect that we don't need a JPATransactionManager,
but if I only use the JTATransactionManager the EntityManager doesn't persist anything in the database, although there is no exception.
Costin Leau
Jul 24th, 2006, 04:33 PM
What is your configuration (is the one above)? Normally this happens if the provider doesn't find the proper JTA manager and the commit/rollback calls don't execute and the jta datasource.
anibal
Jul 25th, 2006, 06:20 AM
No, is not the one above, but it is similar.
I have replaced the jotm transactionmanager with the one from geronimo,
because it didn't work with jotm, but it hasn't solved my problem.
But following are my configuration files, perhaps there is something wrong.
persistence.xml
<persistence xmlns=...>
<persistence-unit name="gozdb"
transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.SybaseAnywhereDialect" />
<property name="hibernate.connection.driver_class"
value="com.sybase.jdbc2.jdbc.SybDriver" />
<property name="hibernate.connection.url"
value="jdbc:sybase:Tds:localhost:2638?SERVICENAME=gozdb" />
<property name="hibernate.connection.username" value="..." />
<property name="hibernate.connection.password" value="..." />
<property name="hibernate.max_fetch_depth" value="3" />
</properties>
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=...>
<bean id="broker" class="org.apache.activemq.broker.BrokerService"
init-method="start" destroy-method="stop">
<property name="persistent" value="false" />
<property name="transportConnectorURIs">
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean>
<bean id="jmsConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<bean
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616</value>
</property>
</bean>
</property>
</bean>
<bean id="destination"
class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="Test" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor" />
<bean class="org.springframework.transaction.aspectj.Annotation TransactionAspect" factory-method="aspectOf">
<property name="transactionManager" ref="jtaTransactionManager" />
</bean>
<bean id="transactionContextManager" class="org.jencks.factory.TransactionContextManagerFactor yBean" />
<bean id="userTransaction" class="org.jencks.factory.GeronimoTransactionManagerFacto ryBean" />
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager">
<property name="userTransaction" ref="userTransaction" />
</bean>
<bean id="listener" class="com.gosys.messaging.MessageListener" />
<bean id="service" class="com.gosys.messaging.Service" />
<bean id="listenerContainer"
class="org.springframework.jms.listener.DefaultMessageLis tenerContainer">
<property name="concurrentConsumers" value="1" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="destination" ref="destination" />
<property name="messageListener" ref="listener" />
<property name="messageSelector" value="customer = 6000005" />
<property name="transactionManager" ref="jtaTransactionManager"/>
</bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="jmsConnectionFactory" />
</property>
<property name="pubSubDomain">
<value>true</value>
</property>
<property name="deliveryPersistent">
<value>true</value>
</property>
<property name="defaultDestination" ref="destination" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean">
<property name="persistenceUnitName" value="gozdb" />
</bean>
</beans>
Is the same effect if I use the entitymanager in a MDP or in a "normal" Bean.
I use the @Transactional Annotation in both cases.
youngm
Oct 12th, 2006, 05:19 PM
Any luck with this? I'm having the same problem. See my post here: http://forum.springframework.org/showthread.php?p=81046#post81046
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.