# Rails 2.1 + Oracle

**URL:** <https://www.ruby-forum.com/t/rails-2-1-oracle/142382>\
**Category:** Rails\
**Created:** [July 7, 2008, 2:19pm UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382 "2008-07-07T14:19:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 7, 2008, 2:19pm UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/1 "2008-07-07T14:19:28Z")

</div>

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  
🙂

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’

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 7, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/2 "2008-07-07T15:34:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 8, 2008, 10:31am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/3 "2008-07-08T10:31:28Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 9, 2008, 12:16am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/4 "2008-07-09T00:16:19Z")

</div>

On Tue, Jul 8, 2008 at 3:31 AM, MR Damien  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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 D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 10, 2008, 8:53am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/5 "2008-07-10T08:53:01Z")

</div>

Greg D. wrote:

> On Tue, Jul 8, 2008 at 3:31 AM, MR Damien  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > 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 D.  
> [http://destiney.com/](http://destiney.com/)

Hi,

The problem is solved (I forgot to use ‘commit’ I have used mysql for  
too long time). Now I have problems with Oracle Sequences (again as  
shown in the first post) …

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 10, 2008, 9:43am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/6 "2008-07-10T09:43:34Z")

</div>

Kent S. wrote:

> On Thu, Jul 10, 2008 at 2:53 AM, MR Damien  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,
> > 
> > ## The problem is solved (I forgot to use ‘commit’ I have used mysql for too long time). Now I have problems with Oracle Sequences (again as shown in the first post) …
> 
> 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
> 
> [http://www.datanoise.com](http://www.datanoise.com)

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

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 10, 2008, 9:28am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/7 "2008-07-10T09:28:55Z")

</div>

On Thu, Jul 10, 2008 at 2:53 AM, MR Damien  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> ## The problem is solved (I forgot to use ‘commit’ I have used mysql for too long time). Now I have problems with Oracle Sequences (again as shown in the first post) …

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

> **[DATANOISE.COM](https://www.datanoise.com/)**
>
> DATANOISE.COM - Contact us for any business inquiries

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 10, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/8 "2008-07-10T12:23:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [July 10, 2008, 11:15am UTC](https://www.ruby-forum.com/t/rails-2-1-oracle/142382/9 "2008-07-10T11:15:05Z")

</div>

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 ?
