Forum: JRuby All new objects get an ID of 1

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
159d448982fbdf2e8ee0394c5051b5c5?d=identicon&s=25 Andy J. (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
        # ... = connection.insert(statement, "#{}
          self.class.primary_key,, 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

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

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?

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
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 -

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.

This topic is locked and can not be replied to.