Forum: Ruby on Rails Transactions with multiple databases

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
782af32c3c95bbef31fe6c90ff1a1a5f?d=identicon&s=25 Petr Cervinka (Guest)
on 2006-01-10 17:41
(Received via mailing list)
hi,
i have problem with transactions and multiple databases.

Object1 and Object2 are two different models/databases with different
connections, when i use only
one model:

Object1.transaction do
   object1.value1 = "123456"
   object1.save
   do_some_error
end

it's ok, error is produced, nothing is commited and database is
unchanged.

when i use 2 models, described  at
http://wiki.rubyonrails.com/rails/pages/HowToUseTr...

Object2.transaction do
   Object1.transaction do
     object1.value1 = "123456"
     object1.save
     do_some_error
   end
end

- error is produced, but object1 is commited and database is changed
- imho transaction is active(autocommit false) only for Object2
connection
- ruby-1.8.4, rails-1.0, dbriver is oci

any idea about this ?

thanks, peter
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-01-10 21:14
(Received via mailing list)
The Agile Book addresses just this situation and advises against using
ActiveRecord for updating multiple databases concurrently. What you are
doing is a simulation of a true multiple database transaction.
01d7a451018ac15518f425078ef00c40?d=identicon&s=25 Phillip Hutchings (Guest)
on 2006-01-10 22:20
(Received via mailing list)
On 11/01/2006, at 5:40 AM, Petr Cervinka wrote:

> hi,
> i have problem with transactions and multiple databases.

For transactions across multiple databases to work right you need two-
phase commit support. Rails doesn't have two phase commit support, so
even if it did work it wouldn't do what you expect.


--
Phillip Hutchings
phillip.hutchings@sitharus.com
This topic is locked and can not be replied to.