File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JPA Certification (OCEJPA) and the fly likes More than one datasource in one transaction is possible ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "More than one datasource in one transaction is possible ?" Watch "More than one datasource in one transaction is possible ?" New topic
Author

More than one datasource in one transaction is possible ?

salih ayan
Ranch Hand

Joined: Apr 23, 2013
Posts: 59
Hi.
my problem is ;
l am using struts1
l have two datasource and in my project l have to insert some data to two different table.

TableA and TableB have different datasource.
And l want to insert some data to the TableA and according to the insertation result of TableA (l meant succes or failure) l must insert data to the TableB.

question is assume that l achieve successfully insert data to the TableA and commit it.But than in insertation operation of TableB become failure, in this case l am deleting rows in TablaA .
are there any way to solve this problem in one transaction

please help
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3336
    
    8
Yes, of course. This is a common requirement and also straight forward to implement. See this: http://stackoverflow.com/questions/2867939/can-i-use-multiple-data-sources-in-a-single-stateless-session-bean-ejb3

However, both (or at least one for 1.5 PC) data sources must be able to participate in 2PC. (You need to google if you don't know 2 or 1.5 Phase Commit). If you are using commercial databases such as Oracle, Sybase, MSSQL, they do support XA transactions.

Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
krishna bala
Ranch Hand

Joined: Jul 20, 2009
Posts: 62
What is the back end you are using?

are you using Spring AOP transactions or Hibernate or EJB or Simple JDBC?


do you need to commit the data in the Table A and Table B irrespective failure?

salih ayan
Ranch Hand

Joined: Apr 23, 2013
Posts: 59
l am using struts1 + jpa + DB2

as id l am using RSA(rational Software architech for websphere)

l need to commit when the all operation success, l meant insertation operation of TablaA and TableB when become success than l want to commit
As you know when we use one datasource, if we want to insert data two different table, during the insertation operation of any table if any exception is occured than all insertation is rolled back
in "catch" part of code block.

Look below code l mean something like that







But waht we can do if we have more than one datasource l can not handle and control all thing in one transaction.
Because there is a table in any database and there is another table in different database.
How they(both tables) can communicate eachother when any exception occurs.

l want to roll back all insertation when any exception occurs

suppose that l achive to insert data to TableA and commited.
All rows are inserted in TableA but than when l insert data to TableB any exception occurs and unable to insert rows to TableB
in this case l want to roll back rows which were inserted before TableA.

Normally in one data source and in one transaction to manage this easy.

But as l explaned situation is different now

Please help


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More than one datasource in one transaction is possible ?