• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to do transaction with EJB/JPA and JDBC

 
everson santos
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do 2 deletes, one managed by jpa and other by jdbc. The jdbc delete is made by jbossesb api, I don't have any control.
I can delete when I do 2 methods for each delete using @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) . But I need the both delete in same transaction, because or delete both or any.

Follow my situation: jboss do an insert on table(jdbc) A and the id generated is used to insert on table(jpa) B. These tables don't have relationship, the id from table A is just a field on table B, no pk or fk.
Table A is created by jboss and has own datasource, table B is created by me and have other datasource, table B is a java @Entity.
The transactions are control by container

How could I do the both delete in same transaction ???



the excetpion










the code from jbossesb api





 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the JPA and JDBC calls trying to update the same table? If so, this is not likely to go well.

Also, what transaction manager/driver settings are you using? An XA driver should support to datasources with different types of persistence technologies.
 
everson santos
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, are different tables. One table I try delete using jpa and other table i try with jdbc( i just call a method delete to do it, all thing about connection, statement ... is encapsulated.)

at moment i can't use xa datasource. But if it is only solution i'll try do that

persistence.xml i have: <jta-data-source>java:senai</jta-data-source>
datasource.xml is <local-tx-datasource>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33716
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
everson santos wrote:at moment i can't use xa datasource. But if it is only solution i'll try do that

You need to use an XA datasource for two different connections to synchronize their commits. If the two tables accessed by the same user id, you could use the same connection. You have to be careful on who commits the transaction though.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic