• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction: Spring2.x + Hibernate3.0 + Jboss + Multiple Databases

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My application uses multiple databases (all with the same structure and one with another). I do some operation on this one dev db and qa db. I need transaction during this operation i.e. i save something to the first db and than to the another. Is it possible to do it in jboss? Do I have to use JtaTransactionManager or can i use i.e. HibernateTransactionManager. Can somebody provide me with some configuration (including transaction) when there are 2 different db (on the same server) and their uses diffrent DAO's and the same transaction manager ? (situation like this)

dev
DAO1
tx1

qa
DAO2
tx1
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajasekhar Bandapalle:
Hi,
My application uses multiple databases (all with the same structure and one with another). I do some operation on this one dev db and qa db. I need transaction during this operation i.e. i save something to the first db and than to the another. Is it possible to do it in jboss?



Yes if you have the Txn Manager properly configured



Do I have to use JtaTransactionManager or can i use i.e. HibernateTransactionManager.



I believe you can use either, although we Arjuna Txn Manager that comes with Jboss (we have JCA connectors that also need to be involved in the Txn)

I'd recommend going to the Jboss site/forums to get specific details as each jboss version has slightly different ways of configuring this (for example we declare a XA txn datasource for each DB, turn on the track by tx then get the spring/hibernate or jboss-service.xml/hibernate config to point to those datasources).

Cheers,
Martijn
 
Rajasekhar Bandapalle
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Martijn.

Do you know how to configure xa in jboss?
if you know, could you please share code with me.

Thanks,
Raj.
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly I'd make sure that you really need XA for your solution. XA is used for managing a global txn across multiple resources and it is therefore quite heavyweight. Sometimes having a single transaction for each resource is good enough (that'll depend on your business requirements)

Configuring XA in Jboss can be quite complex (depending on whether you are involving Database, JMS Messaging, JCA connectors etc). I'm assuming you want to do this for your 2 database model.

1.) You need to make sure your databases are XA capable and have that switched on, Sybase for example require a separate license for XA capability.

2.) You need to set up a whole bunch of configuration in jboss, I recommend starting here:

http://wiki.jboss.org/wiki/ConfigDataSources

I'm also going to add this from Theserverside that I thought was an excellent explanation of the concepts:

---------------

An XA transaction, in the most general terms, is a "global transaction" that may span multiple resources. A non-XA transaction always involves just one resource.

An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).

XA transactions come from the X/Open group specification on distributed, global transactions. JTA includes the X/Open XA spec, in modified form.

Most stuff in the world is non-XA - a Servlet or EJB or plain old JDBC in a Java application talking to a single database. XA gets involved when you want to work with multiple resources - 2 or more databases, a database and a JMS connection, all of those plus maybe a JCA resource - all in a single transaction. In this scenario, you'll have an app server like Websphere or Weblogic or JBoss acting as the Transaction Manager, and your various resources (Oracle, Sybase, IBM MQ JMS, SAP, whatever) acting as transaction resources. Your code can then update/delete/publish/whatever across the many resources. When you say "commit", the results are commited across all of the resources. When you say "rollback", _everything_ is rolled back across all resources.

The Transaction Manager coordinates all of this through a protocol called Two Phase Commit (2PC). This protocol also has to be supported by the individual resources.

In terms of datasources, an XA datasource is a data source that can participate in an XA global transaction. A non-XA datasource generally can't participate in a global transaction (sort of - some people implement what's called a "last participant" optimization that can let you do this for exactly one non-XA item).

For more details - see the JTA pages on java.sun.com. Look at the XAResource and Xid interfaces in JTA. See the X/Open XA Distributed Transaction specification. Do a google source on "Java JTA XA transaction".

--------------
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic