aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to do transaction  with  EJB/JPA and JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to do transaction  with  EJB/JPA and JDBC" Watch "How to do transaction  with  EJB/JPA and JDBC" New topic
Author

How to do transaction with EJB/JPA and JDBC

everson santos
Ranch Hand

Joined: Jul 11, 2009
Posts: 50
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
everson santos
Ranch Hand

Joined: Jul 11, 2009
Posts: 50
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

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
 
subject: How to do transaction with EJB/JPA and JDBC