• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to do transaction with EJB/JPA and JDBC

 
Ranch Hand
Posts: 50
  • 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





 
author & internet detective
Posts: 39392
763
Eclipse IDE VI Editor Java
  • 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
  • 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
Posts: 39392
763
Eclipse IDE VI Editor Java
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!