All new objects get an ID of 1

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

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-always-1-with-jruby-rack-td4467855.html

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