Transactions with multiple databases


#1

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/HowToUseTransactions:

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


#2

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.


#3

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 H.
removed_email_address@domain.invalid