Forum: JRuby All new objects get an ID of 1

C56d14d32eddc6e2bd6364bc2ebbf542?d=identicon&s=25 Andy Joel (f2andy)
on 2012-04-27 15:55
I have a problem with my project; when creating Rails is assigning 1 as
the ID to any instance when it is saved as a record, instead of
assigning the id from the database (though records in the database are
assigned the correct ID).


I have done some digging; in ActiveRecord::Base there is a method
create, which calls insert on the connection object, assigning to id the
returned value.

      def create
        # ...
        self.id = connection.insert(statement, "#{self.class.name}
Create",
          self.class.primary_key, self.id, self.class.sequence_name)

Up to this point, id is nil, however, for some reason it is getting set
to 1 by connection.insert, instead of the new id set when the record is
saved.

Following this through, this looks to be an issue with the JDBC adapter.
ActiveRecord::ConnectionAdapters::JdbcAdapter has a method _execute,
which invokes execute(sql) on an instance of
AtiveRecord::ConnectionAdapters::PostgresJdbcConnection , but I cannot
find where that is defined, and I suspect that that is where the problem
is.

I am making steps towards Rails 3, and it maybe that updating gems has
introduced this problem. It was working fine until recently, and I do
not think the recent changes I have made will have had an effect.
However, I am now at a loss as to how to proceed.

Has anyone else experienced this issue? Any ideas anyone?

Using
JRuby 1.6.7 (Ruby 1.9)
PostgreSQL 8.4
Rails 2.3.14
activerecord-jdbc-adapter 1.2.2
jdbc-postgres 9.1.901
6a22563bd5790a15adc54c8ca772eb22?d=identicon&s=25 Benjamin Browning (Guest)
on 2012-04-27 16:20
(Received via mailing list)
There was a thread on the jruby-dev list about this exact issue a few
months back -
http://ruby.11.n6.nabble.com/saved-model-object-ID...

The consensus was it's a bug in activerecord-jdbc-adapter 1.2.2 and for
Rails 2.x you should stick to 1.2.1 or 1.2.0 for now.

Ben
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.