JRuby, Rails3, and multiple database connections

I am migrating a project from MRI Ruby and Rails 2.x to JRuby and Rails
3. The app is not very complex, but it does use two databases - one
Postgres database that is the main application database, and one SQL
Server database from which I bring in some extra information (I do not
write to this DB or do any migrations on it)

This worked well until the port. Accessing the SQL Server database now
gives this error:

undefined method `identity=’ for
#ActiveRecord::ConnectionAdapters::JdbcColumn:0x13d285f

Oddly enough, if I start “rails console” and use the AR model that is
connected to SQL Server, I can run queries just fine, including the one
that caused the error above.

I spent some time trying to find a minimal repro, and have attached a
ZIP file containing my minimal rails app that is a repro for this
problem. First, some general information. Gems referred to in my
Gemfile:

  • rails 3.0.1
  • activerecord-jdbcpostgresql-adapter 1.1.1
  • activerecord-jdbcmssql-adapter 1.1.1

User is an AR class referencing the postgres database
Registration is an AR class referencing the SQL Server database.

The test controller that produces the problem:

class TestController < ApplicationController
def index
@cur_user = User.find_or_create_by_name(“bob”)
Registration.find_all_by_activation_id(:first)
render :text => “hi”
end
end

Commenting out the line starting with @cur_user causes the problem to
stop happening.

Any ideas what might be going on here? Is this a JRuby or JDBC issue?

Thanks
Andrew

Nick -
I’ll move the discussion to the URL above. Thanks!
Andrew

Hi Andrew, thanks for this report. This is most likely a JDBC issue.
Would you mind copying it to
Pull requests · nicksieger/activerecord-jdbc-adapter · GitHub? Can
you also try to capture the full backtrace for the exception below?

Thanks,
/Nick

On 9 February 2011 03:10, Andrew B. [email protected] wrote:

I am migrating a project from MRI Ruby and Rails 2.x to JRuby and Rails

Can I ask why you have migrated from ruby MRI to jruby?

Two main reasons:

  • Would like to be able to reach out to Java libraries in putting our
    solutions together, allowing us to share code with other Java apps in
    our ecosystem
  • We aren’t hosting software, but selling it. Packing a JRuby based
    Rails app is tons easier. Packaging an MRI Ruby based Rails app has
    proven to be a pain

Andrew

On 11 February 2011 04:06, Andrew B. [email protected] wrote:

Two main reasons:

  • Would like to be able to reach out to Java libraries in putting our
    solutions together, allowing us to share code with other Java apps in
    our ecosystem
  • We aren’t hosting software, but selling it. Packing a JRuby based
    Rails app is tons easier. Packaging an MRI Ruby based Rails app has
    proven to be a pain

I choose jruby only for it’s easy installation and upgrade and for
easy deployment.