[jruby-user] ActiveRecord Derby bug

5 views
Skip to first unread message

Charles Monteiro

unread,
Jun 11, 2013, 4:07:08 PM6/11/13
to Jruby Users List List
Hi, apparently there's a bug that manifests itself in active record assign_attributes at least in the case of Derby, below I have included the sample code and the stack below. The same code but targeting sqllite3 works fine.

I thought that perhaps the schema creation failed silently but I used a derby browser and that column is there.  

"title" does show up in the attribute_method_matchers_cache but fails the test attribute_method? the attributes hash is empty

stack:

/Users/charles/.rvm/rubies/jruby-1.7.4/bin/jruby --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/charles/RubymineProjects/TestActiveRecord/src/simple_derby_sample.rb
-- create_table(:albums)
D, [2013-06-11T15:25:22.228000 #2926] DEBUG -- :    (9.0ms)  SET ISOLATION = SERIALIZABLE
D, [2013-06-11T15:25:22.306000 #2926] DEBUG -- :    (61.0ms)  CREATE TABLE "ALBUMS" ("ID" int GENERATED BY DEFAULT AS identity NOT NULL PRIMARY KEY, "TITLE" varchar(255), "PERFORMER" varchar(255)) 
   -> 1.8110s
   -> 0 rows
-- create_table(:tracks)
   -> 0.0250s
   -> 0 rows
D, [2013-06-11T15:25:22.331000 #2926] DEBUG -- :    (18.0ms)  CREATE TABLE "TRACKS" ("ID" int GENERATED BY DEFAULT AS identity NOT NULL PRIMARY KEY, "ALBUM_ID" integer, "TRACK_NUMBER" integer, "TITLE" varchar(255)) 
ActiveRecord::UnknownAttributeError: unknown attribute: title
  assign_attributes at /Users/charles/.rvm/gems/jruby-1.7.4/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:88
               each at org/jruby/RubyHash.java:1332
  assign_attributes at /Users/charles/.rvm/gems/jruby-1.7.4/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78
         initialize at /Users/charles/.rvm/gems/jruby-1.7.4/gems/activerecord-3.2.13/lib/active_record/base.rb:498
             create at /Users/charles/.rvm/gems/jruby-1.7.4/gems/activerecord-3.2.13/lib/active_record/persistence.rb:44
             (root) at /Users/charles/RubymineProjects/TestActiveRecord/src/simple_derby_sample.rb:34
               load at org/jruby/RubyKernel.java:1073
             (root) at -e:1

Process finished with exit code 1


sample code:


require 'active_record'
require 'activerecord-jdbc-adapter'
require 'logger'

ActiveRecord::Base.logger = Logger.new(STDERR)
#ActiveRecord::Base.colorize_logging = false

ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'org.apache.derby.jdbc.EmbeddedDriver',
:url => 'jdbc:derby:test_db;create=true'
)
ActiveRecord::Schema.define do
create_table :albums do |table|
table.column :title, :string
table.column :performer, :string
end

create_table :tracks do |table|
table.column :album_id, :integer
table.column :track_number, :integer
table.column :title, :string
end
end

class Album < ActiveRecord::Base
has_many :tracks
end

class Track < ActiveRecord::Base
belongs_to :album
end

album = Album.create(:title => 'Black and Blue', :performer => 'The Rolling Stones')
album.tracks.create(:track_number => 1, :title => 'Hot Stuff')
album.tracks.create(:track_number => 2, :title => 'Hand Of Fate')
album.tracks.create(:track_number => 3, :title => 'Cherry Oh Baby ')
album.tracks.create(:track_number => 4, :title => 'Memory Motel ')
album.tracks.create(:track_number => 5, :title => 'Hey Negrita')
album.tracks.create(:track_number => 6, :title => 'Fool To Cry')
album.tracks.create(:track_number => 7, :title => 'Crazy Mama')
album.tracks.create(:track_number => 8,:title => 'Melody (Inspiration By Billy Preston)')

album = Album.create(:title => 'Sticky Fingers',:performer => 'The Rolling Stones')
album.tracks.create(:track_number => 1, :title => 'Brown Sugar')
album.tracks.create(:track_number => 2, :title => 'Sway')
album.tracks.create(:track_number => 3, :title => 'Wild Horses')
album.tracks.create(:track_number => 4,:title => 'Can\'t You Hear Me Knocking')
album.tracks.create(:track_number => 5, :title => 'You Gotta Move')
album.tracks.create(:track_number => 6, :title => 'Bitch')
album.tracks.create(:track_number => 7, :title => 'I Got The Blues')
album.tracks.create(:track_number => 8, :title => 'Sister Morphine')
album.tracks.create(:track_number => 9, :title => 'Dead Flowers')
album.tracks.create(:track_number => 10, :title => 'Moonlight Mile')

puts Album.find(1).tracks.length
puts Album.find(2).tracks.length

puts Album.find_by_title('Sticky Fingers').title
puts Track.find_by_title('Fool To Cry').album_id

Charles Monteiro



Charles Monteiro

unread,
Jun 12, 2013, 4:33:11 PM6/12/13
to us...@jruby.codehaus.org
Ok, I'll re-phrase , is somebody using Derby in an embedded mode with Jruby and thru some ORM successfully ? If so , pray tell. thanks 


Charles Monteiro


Karol Bucek

unread,
Jun 13, 2013, 3:50:39 AM6/13/13
to us...@jruby.codehaus.org

 Hi Charles, as I already mentioned on the issue try using the latest stable/beta of AR-JDBC and/or try changing the following :

ActiveRecord::Base.establish_connection( :adapter => 'derby', :database => 'test_db' )

We do have AR-JDBC users running with Derby/H2/HSQLDB embed DBs and they're mostly doing fine ...

If you're using for other ORMs those supporting JRuby  + JDBC should be just fine e.g. Sequel.

Hope that helps!

K.

Charles Monteiro

unread,
Jun 13, 2013, 5:32:20 AM6/13/13
to us...@jruby.codehaus.org
Ok, I will try the line below. I did use the latest AR_JDBC and when that did not work I tried the beta. Specifically, I would like to use DataMapper and I can't seem to make that work with Derby but I put in a post to their Google group.

Charles Monteiro


Charles Monteiro

unread,
Jun 13, 2013, 10:48:10 AM6/13/13
to us...@jruby.codehaus.org
OK, I now can confirm that I can connect with the  connection parameters provided,  thanks


Charles Monteiro


Karol Bucek

unread,
Jun 14, 2013, 1:54:45 AM6/14/13
to us...@jruby.codehaus.org

Thanks, please mention this (and that you tested with latest) on the issue so we know that it's behaving differently with adapter: jdbc ... it will require fixing.

K.

Charles Monteiro

unread,
Jun 14, 2013, 6:48:20 PM6/14/13
to us...@jruby.codehaus.org
done

Charles Monteiro


Reply all
Reply to author
Forward
0 new messages