|
#1
|
|||
|
|||
|
I have not found clear answers for this, maybe because JPA & JMS are too short words to search for in this forum
![]() Say I have a method which does some updates to db using JPA and sends some messages using JMS. I want the method to execute transactionally. For this I need to use JTA, Spring's own transaction management handling is not enough (correct?). How should I configure the different transactionManagers etc. to achieve this? I am using Spring 2.0.x (although upgrading to 2.5 might be an option in case it is critical). |
|
#2
|
|||
|
|||
|
Quote:
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#3
|
|||
|
|||
|
Yep, that's what I fgured. What I am unsure of is how to configure the JPA, JTA and JMS related settings so that all participate in the JTA transaction nicely.
|
|
#4
|
|||
|
|||
|
Configure them as you normally would. The only difference that instead of a JPATransactionManager you configure a JtaTransactionManager thats it... No more no less...
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#5
|
|||
|
|||
|
I still don't quite get it. How do I configure my JPA entityManager (persistenceManager, or some other bean) to be aware of the JTA transactionManager?
When I use plain JPA (without JTA) my JPA transactionManager and JPA entity manager are connected by the transactionManager config: Code:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
|
|
#6
|
|||
|
|||
|
You don't have to. You only have to make sure that all of your DataSources are XA capable.
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#7
|
|||
|
|||
|
Quote:
Is this documented somewhere, in Spring HTML documentation, or in Javadocs? Or do I need to look at the source code for this kind of information? I have not found much documentation on this, but I found one example on http://erich.soomsam.net/2007/04/. I don't fully understand all the code on that page (which is partly the reason I created this thread). Here, there seems to be lots of configuration for connecting JPA and JTA, such as Code:
<!-- configure Hibernate to participate in JTA transactions using the JOTM transaction manager and
specify further Hibernate specific configuration properties -->
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JOTMTransactionManagerLookup"/>
<entry key="hibernate.transaction.flush_before_completion"
value="true"/>
<entry key="hibernate.transaction.auto_close_session"
value="true"/>
<entry key="hibernate.current_session_context_class"
value="jta"/>
<entry key="hibernate.connection.release_mode"
value="auto"/>
</map>
</property>
Appreciate all the comments, thanks. |
|
#8
|
|||
|
|||
|
It could work with Hibernate, but if you want to do it "by the book" you would have to define the jtadatasource in persistence.xml.
|
|
#9
|
|||
|
|||
|
Quote:
1. use transaction-type="JTA" in persistence.xml 2. define a JTA transaction manager 3. use XA capable dataSources That's it? I don't configure the link between JPA (entityManagers etc) and JTA in any way? Isn't there any documentation on this? What's with all the extra configuration in http://erich.soomsam.net/2007/04/ ? Why doesn't he just do the 3 points from the list above? |
|
#10
|
|||
|
|||
|
The link here is the datasource, you have to make sure that you use the same datasource. For JTA is doesn´t matter what type of transactional resource it is, as long as it it XA capable, which is what you want how else would one integrate JMS and JDBC and ... if you need to make all the specific implementations aware of the JTATransaction.....
Why he does the extra configuration, I have no idea, he could wire them up. I registered a JIRA issue and placed a request for documentation, this issue seems to arise more and more on the forums. Would be nice if we had some reference to point to.
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan Last edited by Marten Deinum; Dec 14th, 2007 at 02:24 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|