db connection returns stale values

Hello,

I’m working on a rails 3 app for a legacy oracle db.

I have a controller that saves object graphs (accepts_nested_attributes_for) but I noticed the post-update JSON response still contains the pre-update values.

After some debugging, it appears the database connection is returning stale values (find(), reload(), etc., all return pre-update values; but SQL clients and other ActiveRecord connections find post-update values, confirming the update was written successfully to the database).

A call to ActiveRecord::Base.establish_connection fixes the problem for the ‘stale’ connection.

controller:

def update

#@default_model.update_attributes(params[@model_name])

@default_model.assign_attributes(params[@model_name])

Graph::Helper.save(@default_model) #custom save() for legacy version control

debugger

@default_model.some_association.updated_field #still shows pre-update value

@default_model.reload

@default_model.some_association.updated_field #still shows pre-update value

@default_model.find(id).some_association.updated_field #still shows pre-update value

ActiveRecord::Base.establish_connection(:oracledb); #THIS LINE SEEMS TO FIX THE PROBLEM.

@default_model.reload

@default_model.some_association.updated_field #shows the correct, updated value.

end

For what it’s worth, I’m using jruby in threadsafe mode with the oracle jdbc activerecord adapter. Any suggestions on where to look to get to the bottom of the stale values?

Thanks,

Tom