Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

hibernate: multiple datasources, one transaction

Thread view: 
pete leg - 21 Sep 2006 08:48 GMT
hi all,
i need to update/modify more than 1 db (on different machines and with
different dbms) so that if one of these actions doesn't work i can roll
back on all the databases involved.

any idea about how to achieve this goal?
thanx in advance
pete
Babu Kalakrishnan - 21 Sep 2006 13:22 GMT
> i need to update/modify more than 1 db (on different machines and with
> different dbms) so that if one of these actions doesn't work i can roll
> back on all the databases involved.
>
> any idea about how to achieve this goal?

Don't think there's anything off the shelf that can do this. As far as I
can recall, you need two separate SessionFactories to handle two
datasources, so you will never have a single Hibernate session that can
handle accesses to the two datasources.

What you could do is to perhaps write a helper class that implements the
Transaction interface and handles two (or more) sessions (i.e internally
creates separate transactions from the 2 sessions, and performs a commit
or rollback on them simultaneously - however, I don't think even this
will solve the problem of a commit on the second database throwing an
exception - because the first commit would have already been performed
by then and you wouldn't be able to roll it back.)

BK
Robert Klemme - 21 Sep 2006 13:31 GMT
>> i need to update/modify more than 1 db (on different machines and with
>> different dbms) so that if one of these actions doesn't work i can roll
[quoted text clipped - 6 lines]
> datasources, so you will never have a single Hibernate session that can
> handle accesses to the two datasources.

The concept is called "distributed transaction".  As far as I can see
Hibernate itself does not deal with that but it can be included in a CMP
scenario in J2EE:

http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.htm
l#configuration-j2ee


> What you could do is to perhaps write a helper class that implements the
> Transaction interface and handles two (or more) sessions (i.e internally
[quoted text clipped - 3 lines]
> exception - because the first commit would have already been performed
> by then and you wouldn't be able to roll it back.)

If hibernate is actually capable of participating in distributed TX that
likely means it is capable of doing two phase commit.  If it does, then
it should be possible to use that for doing transactions across several
hibernate datastores.  You might have to use an external TX coordinator
- or create one yourself.

Kind regards

    robert


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.