JRuby

"Table X does not exist" with embedded Derby on JRuby 1.2 / Rails 2.3.2

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Mac OS 10.5.3, Netbeans 6.1,jruby-1.1.2, rails-2.1.0, activerecord-jdbcmysql-adapter-0.8.1, database is MySQL 5 running on a Solaris 10 box (connection setting is localhost but that tunnels to the solaris box)
  • Number of attachments :
    0

Description

*Attached is a new project I created and is going the same thing.

When I run my database migrationI get an error that the table it just created does not exist. It was able to connect to the mysql 5 db to create the table so I assume the connector is working.

I don't know if the fact that it claims to be looking for "WEB_FORMS" when the table is called "web_forms" is the problem or a red herring. Perhaps the error reporting just displays it in all caps for emphasis.

When I run the app in debug and try to create a new object in the scaffolded view I can trace it to Line 566 of jdbc_adapter.rb:

def jdbc_columns(table_name, name = nil)
@connection.columns(table_name.to_s)
end

Then it goes into the exception handler and I have no idea what caused the exception. At that point table_name is still lower case according to the debugger. Here is my stack trace from the migration:

(in /Users/rosey/Projects/Ruby/MiniSURF)

    • Invoke db:migrate (first_time)
    • Invoke environment (first_time)
    • Execute environment
    • Execute db:migrate
      rake aborted!
      Table WEB_FORMS does not exist
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:69:in `columns_with_query_cache'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:75:in `table'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:70:in `tables'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:61:in `each'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:61:in `tables'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:23:in `dump'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema_dumper.rb:17:in `dump'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:219:in `/usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:218:in `open'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:218:in `/usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:100:in `/usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31:in `/usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake'
      /usr/local/ruby/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:19:in `load'
      /usr/local/ruby/jruby-1.1.2/bin/rake:19
    • Invoke db:schema:dump (first_time)
    • Invoke environment
    • Execute db:schema:dump

Activity

Hide
Don Werve added a comment -

This is a showstopper for the app I'm developing, and I haven't quite tracked down in the source where the problem might be. Running Rails 2.3.2 on JRuby 1.2.0, with Derby via ActiveRecord-JDBC and the EmbeddedDriver for Derby.

rake db:migrate works fine, and I can work with the database in ij, but nothing works from inside Rails; Model.find(:all), Model.create(...), all of them throw the same exception:

script/console:
>> Ticket.find(:all)
ActiveRecord::ActiveRecordError: Table TICKETS does not exist
from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in `columns'
from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1289:in `column_names'
from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2857:in `inspect'
from /opt/jruby/lib/ruby/1.8/irb.rb:302:in `output_value'
from /opt/jruby/lib/ruby/1.8/irb.rb:151:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb.rb:263:in `signal_status'
from /opt/jruby/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /opt/jruby/lib/ruby/1.8/irb.rb:70:in `start'
from /opt/jruby/lib/ruby/1.8/irb.rb:69:in `catch'
from /opt/jruby/lib/ruby/1.8/irb.rb:69:in `start'
from /opt/jruby/bin/jirb:19

The other odd thing is that find(:all) returned an empty array until I manually added a row to the database; create and such have never worked.

A few other odd things:

Ticket.connection.tables
=> []

Ticket.connection.select_all("select * from tickets")
=> [{"id"=>1, "description"=>"foobar"}]

Ticket.connection.select_all("select * from TICKETS")
=> [{"id"=>1, "description"=>"foobar"}]

And a list of my installed gems:

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activerecord-jdbc-adapter (0.9.1)
activerecord-jdbcderby-adapter (0.9.1)
activeresource (2.3.2)
activesupport (2.3.2)
jdbc-derby (10.4.2.0)
jruby-openssl (0.4)
rails (2.3.2)
rake (0.8.4)
rspec (1.2.2, 1.2.0)
sources (0.0.1)
warbler (0.9.12)

Any ideas? Am I missing something simple, or...?

Show
Don Werve added a comment - This is a showstopper for the app I'm developing, and I haven't quite tracked down in the source where the problem might be. Running Rails 2.3.2 on JRuby 1.2.0, with Derby via ActiveRecord-JDBC and the EmbeddedDriver for Derby. rake db:migrate works fine, and I can work with the database in ij, but nothing works from inside Rails; Model.find(:all), Model.create(...), all of them throw the same exception: script/console: >> Ticket.find(:all) ActiveRecord::ActiveRecordError: Table TICKETS does not exist from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in `columns' from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1289:in `column_names' from /opt/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2857:in `inspect' from /opt/jruby/lib/ruby/1.8/irb.rb:302:in `output_value' from /opt/jruby/lib/ruby/1.8/irb.rb:151:in `eval_input' from /opt/jruby/lib/ruby/1.8/irb.rb:263:in `signal_status' from /opt/jruby/lib/ruby/1.8/irb.rb:147:in `eval_input' from /opt/jruby/lib/ruby/1.8/irb.rb:146:in `eval_input' from /opt/jruby/lib/ruby/1.8/irb.rb:70:in `start' from /opt/jruby/lib/ruby/1.8/irb.rb:69:in `catch' from /opt/jruby/lib/ruby/1.8/irb.rb:69:in `start' from /opt/jruby/bin/jirb:19 The other odd thing is that find(:all) returned an empty array until I manually added a row to the database; create and such have never worked. A few other odd things: Ticket.connection.tables => [] Ticket.connection.select_all("select * from tickets") => [{"id"=>1, "description"=>"foobar"}] Ticket.connection.select_all("select * from TICKETS") => [{"id"=>1, "description"=>"foobar"}] And a list of my installed gems: actionmailer (2.3.2) actionpack (2.3.2) activerecord (2.3.2) activerecord-jdbc-adapter (0.9.1) activerecord-jdbcderby-adapter (0.9.1) activeresource (2.3.2) activesupport (2.3.2) jdbc-derby (10.4.2.0) jruby-openssl (0.4) rails (2.3.2) rake (0.8.4) rspec (1.2.2, 1.2.0) sources (0.0.1) warbler (0.9.12) Any ideas? Am I missing something simple, or...?
Hide
Don Werve added a comment -

Think I found the problem. For embedded databases, you don't need to specify usernames and passwords, and derby_schema is being set by @config[:username]... which is nil, for me.

Removing derby_schema from the calls made in tables() and columns() in jdbc_adapter/jdbc_derby.rb fixed the problem for me. I'll need to set up a client/server Derby and see if it works there as well, and if not, set up code for both cases.

How should I contribute a patch once I've got this sorted?

Show
Don Werve added a comment - Think I found the problem. For embedded databases, you don't need to specify usernames and passwords, and derby_schema is being set by @config[:username]... which is nil, for me. Removing derby_schema from the calls made in tables() and columns() in jdbc_adapter/jdbc_derby.rb fixed the problem for me. I'll need to set up a client/server Derby and see if it works there as well, and if not, set up code for both cases. How should I contribute a patch once I've got this sorted?
Hide
Thomas E Enebo added a comment -

You can attach any fixes (in patch format) as an attachment.

Show
Thomas E Enebo added a comment - You can attach any fixes (in patch format) as an attachment.
Hide
Charles Oliver Nutter added a comment -

Don: And thanks for doing the extra homework on this, it's really appreciated. Toss us a patch and we'll get it in.

Show
Charles Oliver Nutter added a comment - Don: And thanks for doing the extra homework on this, it's really appreciated. Toss us a patch and we'll get it in.
Hide
Dean Holdren added a comment -

I have the same issue with JNDI (Oracle) in JBOSS.
getting "Table COMMENTS does not exist"

I'm using:
warbler 0.9.13
rails 2.3.2
activerecord-jdbc-adapter 0.9.1
jboss 4.0.5

Show
Dean Holdren added a comment - I have the same issue with JNDI (Oracle) in JBOSS. getting "Table COMMENTS does not exist" I'm using: warbler 0.9.13 rails 2.3.2 activerecord-jdbc-adapter 0.9.1 jboss 4.0.5
Hide
James Lavin added a comment -

[Posted previously to http://jira.codehaus.org/browse/JRUBY-2618, but should have posted here.]

I'm running into this too, with Rails 2.3.2 on JRuby 1.3.1 (plus activerecord-jdbc-adapter (0.9.1)
activerecord-jdbcderby-adapter (0.9.1)), using embedded Derby.

I can create a table just fine using either ActiveRecord or JRuby+java.sql. But I can't use it in ActiveRecord as I can with JRuby+java.sql.

I suspect ActiveRecord is quoting the table name, which Derby doesn't seem to allow.

Within "java org.apache.derby.tools.ij", I try to view a table:

ij> select * from system_settings;
[SHOWS CORRECT OUTPUT]
ij> select * from 'system_settings';
ERROR 42X01: Syntax error: Encountered "\'system_settings\'" at line 1, column 15.
ij> select * from "system_settings";
ERROR 42X05: Table/View 'system_settings' does not exist.

I'm guessing the ActiveRecord error message (".../jruby-1.3.1/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in `columns': Table EMPLOYEES does not exist (ActiveRecord::ActiveRecordError)") is because AR is double-quoting the table name.

Show
James Lavin added a comment - [Posted previously to http://jira.codehaus.org/browse/JRUBY-2618, but should have posted here.] I'm running into this too, with Rails 2.3.2 on JRuby 1.3.1 (plus activerecord-jdbc-adapter (0.9.1) activerecord-jdbcderby-adapter (0.9.1)), using embedded Derby. I can create a table just fine using either ActiveRecord or JRuby+java.sql. But I can't use it in ActiveRecord as I can with JRuby+java.sql. I suspect ActiveRecord is quoting the table name, which Derby doesn't seem to allow. Within "java org.apache.derby.tools.ij", I try to view a table: ij> select * from system_settings; [SHOWS CORRECT OUTPUT] ij> select * from 'system_settings'; ERROR 42X01: Syntax error: Encountered "\'system_settings\'" at line 1, column 15. ij> select * from "system_settings"; ERROR 42X05: Table/View 'system_settings' does not exist. I'm guessing the ActiveRecord error message (".../jruby-1.3.1/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in `columns': Table EMPLOYEES does not exist (ActiveRecord::ActiveRecordError)") is because AR is double-quoting the table name.
Hide
James Lavin added a comment -

I tried the fix proposed by Don Werve, and it does seem to work. (Though I've run only a single test so far.)

I don't know how to submit a formal patch, but here's all I had to change in jruby-1.3.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_derby.rb:

def columns(table_name, name=nil)
@connection.columns_internal(table_name.to_s, name)
#@connection.columns_internal(table_name.to_s, name, derby_schema)
end

def tables
@connection.tables(nil)
#@connection.tables(nil, derby_schema)
end

Show
James Lavin added a comment - I tried the fix proposed by Don Werve, and it does seem to work. (Though I've run only a single test so far.) I don't know how to submit a formal patch, but here's all I had to change in jruby-1.3.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_derby.rb: def columns(table_name, name=nil) @connection.columns_internal(table_name.to_s, name) #@connection.columns_internal(table_name.to_s, name, derby_schema) end def tables @connection.tables(nil) #@connection.tables(nil, derby_schema) end
Hide
Nick Sieger added a comment -

I pushed a fix that allows you to set schema explicitly in ar-jdbc 175b8152.

Show
Nick Sieger added a comment - I pushed a fix that allows you to set schema explicitly in ar-jdbc 175b8152.

People

Vote (3)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: