> 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