1

Hello Folks,

I have a requirement like i have to perform CRUD operations in(to) different DataBase say SQL and ORACLE, in same transaction. Is there a way to achieve that ?

(1) Is it possible to achieve this using one SessionFactory, if yes then how?

(2) Is it possible to do it using two different Sessionfactory, if then how ?

Only condition i have is when i fire one query to insert it should insert to both DataBases at same time.

I hope iam very clear with my question. Waiting for your reply.

arun_kk
  • 382
  • 2
  • 5
  • 14
  • 1
    http://stackoverflow.com/questions/10212274/two-phase-commit-2pc-configuration-with-atomikos you might also want to google JTA – G-Man Dec 03 '12 at 13:23

1 Answers1

0

You can use global transactions. This is specified in the Java Transaction API. Many application servers do support that using a proprietary transaction manager which can in turn be used in your session factory. Underlying idea is using the two phase commit protocol which must be supported by your databases (they need to understand the prepare command). These drivers are usually found looking for XA compatibility. Oracle's Weblogic app server e.g. already ships with a XA compliant Oracle driver. Anyway, this may be different for other app servers.

JTA bases on XOpen XA, you should read through that to get the big picture.

G-Man provided a good link on a configuration of Atomikos, for the case your app server doesn't provide a suitable TA manager or you do not want to use an app server.

sorencito
  • 2,517
  • 20
  • 21