Rails 2.1 + Oracle

Hi all,

I am completely new to use Oracle with Rails (was using MySQL before). I
have some trouble to get my code work despite the rails abstraction.

My code was working perfectly with MySQL, but now when I am trying to
save some objects with a :though relation.

So I have a request objects with many relation to others. When I do
request.save I get an OCIError.
I saw that usually ORA-02289 was a problem of rights in the database but
in this case, the user have all rights. rake db:migrate get no errors at
all.

If someone have more experience with Rails and Oracle, you are welcome
:slight_smile:

OCIError (ORA-02289: sequence does not exist):
    stmt.c:539:in oci8lib.so
    c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:753:in
`exec'
    c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:142:in
`do_ocicall'
    c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:753:in
`exec'
    c:/ruby/lib/ruby/gems/1.8/gems/ruby-oci8-1.0.2-x86-mswin32/lib/oci8.rb:255:in
`exec'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:700:in
`exec'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:229:in
`next_sequence_value'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2493:in
`create_without_callbacks'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:220:in
`create_without_timestamps'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/timestamp.rb:29:in
`create'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2472:in
`create_or_update_without_callbacks'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:207:in
`create_or_update'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2206:in
`save_without_validation!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:911:in
`save_without_dirty!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:83:in
`save_without_transactions!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
`save!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:79:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:98:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
`save!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:118:in
`rollback_active_record_state!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in
`save!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:882:in
`create!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:in
`insert_record'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1852:in
`with_scope'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:in
`send'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_through_association.rb:61:in
`insert_record'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:in
`send'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:in
`after_create_or_update_associated_records_for_services'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:274:in
`method_missing'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
`method_missing'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
`each'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
`send'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:175:in
`method_missing'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:274:in
`method_missing'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1215:in
`after_create_or_update_associated_records_for_services'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:in
`send'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:173:in
`evaluate_method'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:161:in
`call'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:93:in
`run'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:in
`each'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:in
`send'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:92:in
`run'
    c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/callbacks.rb:272:in
`run_callbacks'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:298:in
`callback'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:221:in
`create_without_timestamps'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/timestamp.rb:29:in
`create'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2472:in
`create_or_update_without_callbacks'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:207:in
`create_or_update'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2200:in
`save_without_validation'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:901:in
`save_without_dirty'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:75:in
`save_without_transactions'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:in
`save'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:79:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:98:in
`transaction'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:in
`save'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:118:in
`rollback_active_record_state!'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:106:in
`save'

Ok, I got it to work with enhanced oracle adapter. I think the problems
came from the timestamp column which seems not to be well supported by
the 'standard' oracle adapter.

Hi Again,

It seems that using Oracle with Rails is a little bit more complex than
with MySQL.

Is someone is aware of some caching process with Oracle, because I have
the following code:

account_check = AccountRequest.find_by_login(user)

if account_check
flash.now[:notice] = "A request is already pending for this user"
return
end

And despite the fact I have remove all entries in the account_requests
table, the controller still get some old data by oracle when I refresh
the page.

How can I solve this ?

Are you removing them in such a way that Rails knows?

AccountRequest.destroy_all

Also, a newer Oracle has the recycle bin feature, and you may find
calling `execute "purge recyclebin"` helpful.

Greg Donald wrote:

Oracle adapter assumes that you have "${table_name}_seq" sequence
defined for each of your tables. Also you can override the sequence
name with ActiveRecord::Base.set_sequence_name method.

Kent Sibilev wrote:

MR Damien wrote:

I have a sequence for all table but the joined tables (used by has_many
:though), perhaps because of the :id => false option.

Now I removed all :id => false from join table, I have a problem of
ORA-00972: identifier is too long for sequences.

Do you know how to shorten the name of sequences ?

MR Damien wrote:

MR Damien wrote:

I have a sequence for all table but the joined tables (used by has_many
:though), perhaps because of the :id => false option.

Now I removed all :id => false from join table, I have a problem of
ORA-00972: identifier is too long for sequences.

Do you know how to shorten the name of sequences ?

I solved that by shortening the table name