Forum: Ruby on Rails JRuby-Oracle Error - Part 2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
439a9cebe73c87771d06723f6027bfed?d=identicon&s=25 Norman Smith (smithno)
on 2009-05-06 16:28
My app is using JRuby on Rails and Oracle. I have a join table that has
not ID column. When I create the table via db:migrate, no Oracle
Sequence is set up for it. Later when I populate the table with data, I
get an error that the sequence for the table doesn't exist. The
db:migrate error is:

==  UpdatePackagesValues: migrating ====================================
rake aborted!
An error has occurred, all later migrations canceled:

ActiveRecord::ActiveRecordError: ORA-02289: sequence does not exist
: select packages_values_seq.nextval id from dual

I am using ActiveRecord-JDBC (0.5) and activerecord-jdbc-adapter (0.8)
gems for accessing the database. The current 0.9.1 adapter has several
problems that I can't work around. This feels like bug in
activerecord-jdbc-adapter (0.8) and I can work around it by manually
creating the Oracle Sequence object.

Also related is the fact that the Oracle Sequence Objects default to
starting at 10000. Is this an Oracle thing or can it be configured in
the adapter? I think I can get around this issue for now by manually
deleting and recreating the Sequence Objects before any data is loaded
into the database.

Norm
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2009-05-06 17:01
(Received via mailing list)
On Wed, May 6, 2009 at 9:28 AM, Norman Smith
<rails-mailing-list@andreas-s.net> wrote:
>
> starting at 10000. Is this an Oracle thing or can it be configured in
> the adapter? I think I can get around this issue for now by manually
> deleting and recreating the Sequence Objects before any data is loaded
> into the database.


I found similar issues with the OracleEnhanced driver.  I fixed things
up like this:

module ActiveRecord
  module ConnectionAdapters
    class OracleEnhancedAdapter
      def create_table(name, options = {}) #:nodoc:
        super(name, options)
        seq_name = options[:sequence_name] || "#{name}_seq"
        execute "CREATE SEQUENCE #{seq_name} START WITH 1 INCREMENT BY
1 NOCACHE ORDER NOCYCLE" unless options[:id] == false
      end
    end
    module SchemaStatements
      def add_index(table_name, column_name, options = {})
        column_names = Array(column_name)
        index_name   = index_name(table_name, :column => column_names)
        if Hash === options # legacy support, since this param was a
string
          # add support for Oracle bitmap indexes
          index_type = options[:unique] ? "UNIQUE" : options[:bitmap]
? "BITMAP" : ""
          index_name = options[:name] || index_name
        else
          index_type = options
        end
        quoted_column_names = column_names.map { |e|
quote_column_name(e) }.join(", ")
        execute "CREATE #{index_type} INDEX
#{quote_column_name(index_name)} ON #{quote_table_name(table_name)}
(#{quoted_column_names})"
      end
    end
  end
end



--
Greg Donald
http://destiney.com/
This topic is locked and can not be replied to.