JRuby trunk – issues with JDBC connectivity

Following the book on JRuby I am discovering small differences when trying the examples. After installing activerecord-jdbc gem which is available in version 0.5, the shoplet application fails with Rails 2.0, as soon as you click on the ‘About your application environment’ link.

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.2 available at 0.0.0.0:3000
** Use CTRL-C to stop.

Processing InfoController#properties (for 127.0.0.1 at 2007-12-23 23:13:25) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--9791be23205677745e457b5bf62c50eba6e3813f
Parameters: {"controller"=>"rails/info", "action"=>"properties"}
Exception in thread "Ruby Thread11043409" java.lang.NoSuchMethodError: org.jruby.runtime.builtin.IRubyObject.setInstanceVariable(Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject;
at JdbcAdapterInternalService.set_connection(JdbcAdapterInternalService.java:122)
at JdbcAdapterInternalServiceInvoker$set_connection_FS1.call(Unknown Source)
at org.jruby.runtime.callback.FastInvocationCallback.execute(FastInvocationCallback.java:55)
at org.jruby.internal.runtime.methods.SimpleCallbackMethod.call(SimpleCallbackMethod.java:70)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:103)
at org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1092)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:345)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:147)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:76)
at org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1734)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:474)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1499)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:442)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)

I found out that there is newer version of activerecord-jdbc, which is also renamed to activerecord-jdbc-adapter. It is important to uninstall the old gem as well as install the new one, otherwise the application will not work.

$ jruby -S gem install activerecord-jdbc-adapter
Successfully installed activerecord-jdbc-adapter-0.7
1 gem installed
Installing ri documentation for activerecord-jdbc-adapter-0.7...
Installing RDoc documentation for activerecord-jdbc-adapter-0.7...
$ jruby -S gem install activerecord-jdbcmysql-adapter
Successfully installed jdbc-mysql-5.0.4
Successfully installed activerecord-jdbcmysql-adapter-0.7
2 gems installed
Installing ri documentation for jdbc-mysql-5.0.4...
Installing ri documentation for activerecord-jdbcmysql-adapter-0.7...
Installing RDoc documentation for jdbc-mysql-5.0.4...
Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.7...

$ jruby -S gem list activerecord

*** LOCAL GEMS ***

activerecord (2.0.2, 1.15.6)
ActiveRecord-JDBC (0.5)
activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

$ gem uninstall ActiveRecord-JDBC
Successfully uninstalled ActiveRecord-JDBC-0.5
miroslav-adamys-macbook-pro:shoplet miro$ gem list ActiveRecord-JDBC

*** LOCAL GEMS ***

activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

After this, everything works and shoplet connects to database – as you can see from the console log.

Advertisements

9 Responses to JRuby trunk – issues with JDBC connectivity

  1. Hans Doggen says:

    Thanks! Finally a solution to this problem. There was a bug report and it was closed, but it was not clear enough (http://jira.codehaus.org/browse/JRUBY-1698). I think it would be a good idea if you also add this remark to the bug (so people can find the solution easier)

  2. Miro says:

    That is a good idea, Hans. I posted the link to this post as comment.

  3. pH says:

    Hi, two remarks :

    1) shouldn’t the last line read

    jurby -S gem uninstall ActiveRecord-JDBC

    ?

    2) I am struggling with running my migrations .. I tried ‘jruby -S rake db:migrate’, but all I can get is :

    rake aborted!
    Don’t know how to build task ‘drop’

    I though it would be a bad install of some gem, or my driver, or anything … where could I find / ask for some help on this ?

  4. Miro says:

    @pH:
    Yes, it would be safer and less confusing to stick with single way. If your environment PATH has jruby before than ruby directories, the later way works OK as well.

    Ad2: do not know answer ready, sorry. If I figure it out, will let you know …

  5. Aye says:

    Thanks Miro. Definitely helped me get started on using the new glassfish gem.

  6. The funny thing about this is that a freshly new app doesn’t show this behaviour. Just saw it happening on the app migration I am working right now. Anyway, thanks, this was of much help! 😉

  7. Richard Forster says:

    If you are migrating from an earlier version of rails you may need to change the database gem reference in environment.rb:

    from
    gem ‘ActiveRecord-JDBC’
    to
    gem ‘activerecord-jdbc-adapter’

  8. […] me to drop the ActiveRecord-JDBC gem and install activerecord-jdbcmysql-adapter (as described by Miro and Arun Gupta, and even better on the JRuby site).  Still I was stuck in the starting gate as I […]

  9. Vance says:

    Thanks, Miro!

%d bloggers like this: