Null id errors with model containing field named 'TABLEID', borken after 1.2.4

閲覧: 117 回
最初の未読メッセージにスキップ

mark duncan

未読、
2010/09/27 5:47:092010/09/27
To: oracle-...@googlegroups.com
Hi,

I recently upgraded OAA from 1.2.4 but had to rollback after some errors came to light. I started getting 'Cannot insert NULL into subupgrade.subupgradeid...' errors on one table, the only difference i could see that would mark out this one is that it contains a field named TABLEID that i suspect is throwing a spanner in the works. I could create a before_save to grab a new id from the tables sequence and set it manually but i thought i'd check and see if anyone had a better solution.

Cheers

Mark

Raimonds Simanovskis

未読、
2010/09/27 12:27:092010/09/27
To: Oracle enhanced adapter for ActiveRecord
Could you provide more information - tables and columns, model class
definition, which method gave this error and stack trace of this
error?

Raimonds

happs74

未読、
2010/09/27 12:35:042010/09/27
To: Oracle enhanced adapter for ActiveRecord
Hi Raimonds,

I'll get the full details tomorrow but i can replicate in console,
error occurs when i perform a save. The Class def is fairly
straightforward:

# == Schema Information
# Schema version: 20090820093819
#
# Table name: subupgrade
#
# subupgradeid :integer(10) not null, primary key
# tablename :string(32)
# subscriptionid :integer(11)
# tableid :integer(10)
# prodcode :string(64)
# quantity :integer(3)
# status :string(32)
# contactid :integer(11)
#

class Subupgrade < ActiveRecord::Base
# Not using Rails defaults, set table details
set_table_name 'subupgrade'
set_primary_key 'subupgradeid'
set_sequence_name 'subupgrade_seq'

# References
belongs_to :subscription, :foreign_key => 'subscriptionid'
belongs_to :contact, :foreign_key => 'contactid'
end

I'll get a full stacktrace tomorrow morning when i'm back in work.


Cheers

Mark






On Sep 27, 5:27 pm, Raimonds Simanovskis

happs74

未読、
2010/09/27 19:17:482010/09/27
To: Oracle enhanced adapter for ActiveRecord
Here's the stacktrace of creating and saving a record in 1.2.4 and
1.3.1

markd@sulaco:~/rails/crm2_restyle$ script/console
Loading development environment (Rails 2.3.5)
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/
gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is
deprecated and will be removed on or after August 2010. Use
#requirement
>> s = Subupgrade.new
=> #<Subupgrade subupgradeid: nil, tablename: nil, subscriptionid:
nil, tableid: nil, prodcode: nil, quantity: nil, status: nil,
contactid: nil>
>> s.tablename = 'testing 1.2.4'
=> "testing 1.2.4"
>> s.save
=> true
>> s.id
=> 100010040
>> exit

markd@sulaco:~/rails/crm2_restyle$ script/console
Loading development environment (Rails 2.3.5)
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/
gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is
deprecated and will be removed on or after August 2010. Use
#requirement
>> s = Subupgrade.new
=> #<Subupgrade subupgradeid: nil, tablename: nil, subscriptionid:
nil, tableid: nil, prodcode: nil, quantity: nil, status: nil,
contactid: nil>
>> s.tablename = 'testing 1.3.1'
=> "testing 1.3.1"
>> s.save
ActiveRecord::StatementInvalid: OCIError: ORA-01400: cannot insert
NULL into ("ICRM"."SUBUPGRADE"."SUBUPGRADEID"): INSERT INTO
"SUBUPGRADE" ("TABLEID", "QUANTITY", "SUBSCRIPTIONID", "PRODCODE",
"TABLENAME", "CONTACTID", "STATUS") VALUES(NULL, NULL, NULL, NULL,
'testing 1.3.1', NULL, NULL) RETURNING "SUBUPGRADEID" INTO :insert_id
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/connection_adapters/abstract_adapter.rb:219:in `log'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-
adapter-1.3.1/lib/active_record/connection_adapters/
oracle_enhanced_adapter.rb:948:in `log'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-
adapter-1.3.1/lib/active_record/connection_adapters/
oracle_enhanced_adapter.rb:429:in `execute'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-
adapter-1.3.1/lib/active_record/connection_adapters/
oracle_enhanced_adapter.rb:453:in `insert_sql'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/connection_adapters/abstract/database_statements.rb:
44:in `insert_without_query_dirty'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/connection_adapters/abstract/query_cache.rb:18:in
`insert'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/base.rb:2908:in `create_without_timestamps'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/timestamp.rb:53:in `create_without_callbacks'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/callbacks.rb:266:in `create'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/base.rb:2874:in `create_or_update_without_callbacks'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/callbacks.rb:250:in `create_or_update'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/base.rb:2538:in `save_without_validation'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/validations.rb:1078:in `save_without_dirty'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/dirty.rb:79:in `save_without_transactions'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:229:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:229:in
`with_transaction_returning_status'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/connection_adapters/abstract/database_statements.rb:
136:in `transaction'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:182:in `transaction'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:228:in
`with_transaction_returning_status'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:196:in `save'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:208:in `rollback_active_record_state!'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/
active_record/transactions.rb:196:in `save'
from (irb):4>>

Raimonds Simanovskis

未読、
2010/09/28 9:44:022010/09/28
To: Oracle enhanced adapter for ActiveRecord
Tried to repeat your problem but for me everything works, see my test
example https://gist.github.com/bfaa59b302d2245d46e3

Can you do in SQL*Plus
DESC subupgrade
and
DESC subupgrade_seq
?

Somehow it seems that subupgradeid is not recognized as primary key
for this column.
And can you look in log/development.log what SQL statements are
executed and try them manually as well - maybe you will find which SQL
statement is not returning expected results.

Raimonds

mark duncan

未読、
2010/09/28 10:01:112010/09/28
To: oracle-...@googlegroups.com
DESC subupgrade output:

 Name                       Null?    Type
 -----------------------------------------
 SUBUPGRADEID                   NOT NULL NUMBER(10)
 TABLENAME                        VARCHAR2(32)
 SUBSCRIPTIONID                     NUMBER(11)
 TABLEID                        NUMBER(10)
 PRODCODE                        VARCHAR2(64)
 QUANTITY                        NUMBER(3)
 STATUS                         VARCHAR2(32)
 CONTACTID                        NUMBER(11)


I can't desc sequences but it was created with: create sequence subupgrade_seq start with 100000000

Here is the stacktrace when the error occurs in app, the sql looks a little unusual to my eye:

General Error occured : #<ActiveRecord::StatementInvalid: OCIError: ORA-01400: cannot insert NULL into ("ICRM"."SUBUPGRADE"."SUBUPGRADEID"):
INSERT INTO "SUBUPGRADE" ("TABLEID", "QUANTITY", "SUBSCRIPTIONID", "PRODCODE", "TABLENAME", "CONTACTID", "STATUS")
VALUES(100010028, 100, 100010246, 'EASYE100BW000Y', 'WEBMAP', 100010000, 'ACTIVE') RETURNING "SUBUPGRADEID" INTO :insert_id> -
OCIError: ORA-01400: cannot insert NULL into ("ICRM"."SUBUPGRADE"."SUBUPGRADEID"): INSERT INTO "SUBUPGRADE"
("TABLEID", "QUANTITY", "SUBSCRIPTIONID", "PRODCODE", "TABLENAME", "CONTACTID", "STATUS")
VALUES(100010028, 100, 100010246, 'EASYE100BW000Y', 'WEBMAP', 100010000, 'ACTIVE') RETURNING "SUBUPGRADEID" INTO :insert_id

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:948:in `log'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:429:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:453:in `insert_sql'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in `insert_without_query_dirty'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2908:in `create_without_timestamps'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/timestamp.rb:53:in `create_without_callbacks'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:266:in `create'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2874:in `create_or_update_without_callbacks'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:250:in `create_or_update'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2555:in `save_without_validation!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1088:in `save_without_dirty!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:87:in `save_without_transactions!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:200:in `save!'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:856:in `insert_subupgrade'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:371:in `process_order_line'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in `each'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in `process_order_line'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `each'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction'
/home/markd/rails/crm2_restyle/app/models/processorder.rb:61:in `initialize'
/home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in `new'
/home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in `processorder'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction'
/home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:45:in `processorder'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1331:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:617:in `call_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/usr/local/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/metal.rb:47:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
/home/markd/rails/crm2_restyle/app/middleware/flash_session_cookie_middleware.rb:55:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/utils.rb:184:in `safe_fork'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:163:in `start'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/bin/passenger-spawn-server:61


--
You received this message because you are subscribed to the Google Groups "Oracle enhanced adapter for ActiveRecord" group.
To post to this group, send email to oracle-...@googlegroups.com.
To unsubscribe from this group, send email to oracle-enhanc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/oracle-enhanced?hl=en.


happs74

未読、
2010/09/28 10:25:292010/09/28
To: Oracle enhanced adapter for ActiveRecord
If it helps any i'm using Oracle 9i
> `safe_fork' ...
>
> read more »

Raimonds Simanovskis

未読、
2010/09/28 10:26:082010/09/28
To: Oracle enhanced adapter for ActiveRecord
INSERT without value for SUBUPGRADEID and with
RETURNING "SUBUPGRADEID" INTO :insert_id
clause is generated when next primary key value cannot be fetched from
sequence.

Do you see SELECT NEXTVAL FROM subupgrade_seq in development.log
before this failing INSERT statement?

And even better go to lib/active_record/base.rb file in your installed
activerecord 2.3.5 gem and find line
self.id = connection.next_sequence_value(self.class.sequence_name)
and put some debug messages around it to find out if sequence value is
or not fetched correctly

Raimonds
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract_adapter.rb:219:in
> `log'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:948:in
> `log'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:429:in
> `execute'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:453:in
> `insert_sql'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:44:in
> `insert_without_query_dirty'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/query_cache.rb:18:in
> `insert'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2908:in
> `create_without_timestamps'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/time stamp.rb:53:in
> `create_without_callbacks'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/call backs.rb:266:in
> `create'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2874:in
> `create_or_update_without_callbacks'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/call backs.rb:250:in
> `create_or_update'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2555:in
> `save_without_validation!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/vali dations.rb:1088:in
> `save_without_dirty!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirt y.rb:87:in
> `save_without_transactions!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:208:in
> `rollback_active_record_state!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:856:in
> `insert_subupgrade'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:371:in
> `process_order_line'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in `each'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in
> `process_order_line'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `each'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:61:in `initialize'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in
> `new'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in
> `processorder'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:45:in
> `processorder'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ba se.rb:1331:in
> `send'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ba se.rb:1331:in
> `perform_action_without_filters'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fi lters.rb:617:in
> `call_filters'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fi lters.rb:610:in
> `perform_action_without_benchmark'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/be nchmarking.rb:68:in
> `perform_action_without_rescue'
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/co re_ext/benchmark.rb:17:in
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/st ring_coercion.rb:25:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24: in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/pa rams_parser.rb:15:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/metal.rb:47:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/se ssion/cookie_store.rb:93:in
> `call'
> /home/markd/rails/crm2_restyle/app/middleware/flash_session_cookie_middlewa re.rb:55:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fa ilsafe.rb:26:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in
> `synchronize'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/di spatcher.rb:114:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/re loader.rb:34:in
> `run'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/di spatcher.rb:108:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/ra ck/request_handler.rb:92:in
> `process_request'
> /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/ab stract_request_handler.rb:207:in
> `main_loop'
> /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/ra ilz/application_spawner.rb:418:in
> `start_request_handler'
> /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/ra ilz/application_spawner.rb:358:in
> `handle_spawn_application'
> /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/ut ils.rb:184:in
> `safe_fork' ...
>
> read more »

Raimonds Simanovskis

未読、
2010/09/28 10:32:592010/09/28
To: Oracle enhanced adapter for ActiveRecord
INSERT statement without primary key value and with RETURNING clause
is generated only if primary key value cannot be fetched from sequence
(like in this case).

Can you see
SELECT subupgrade_seq.NEXTVAL id FROM dual
in log file before this failing INSERT statement?

And even better go to source of active_record 2.3.5 gem and go to file
lib/active_record/base.rb and fine line
self.id = connection.next_sequence_value(self.class.sequence_name)
and put debug messages around it to find out if next sequence value is
fetched in your case.

Raimonds
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract_adapter.rb:219:in
> `log'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:948:in
> `log'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:429:in
> `execute'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.3. 1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:453:in
> `insert_sql'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:44:in
> `insert_without_query_dirty'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/query_cache.rb:18:in
> `insert'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2908:in
> `create_without_timestamps'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/time stamp.rb:53:in
> `create_without_callbacks'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/call backs.rb:266:in
> `create'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2874:in
> `create_or_update_without_callbacks'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/call backs.rb:250:in
> `create_or_update'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base .rb:2555:in
> `save_without_validation!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/vali dations.rb:1088:in
> `save_without_dirty!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirt y.rb:87:in
> `save_without_transactions!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:208:in
> `rollback_active_record_state!'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:200:in
> `save!'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:856:in
> `insert_subupgrade'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:371:in
> `process_order_line'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in `each'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:355:in
> `process_order_line'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `each'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:62:in `initialize'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /home/markd/rails/crm2_restyle/app/models/processorder.rb:61:in `initialize'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in
> `new'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:46:in
> `processorder'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/conn ection_adapters/abstract/database_statements.rb:136:in
> `transaction'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/tran sactions.rb:182:in
> `transaction'
> /home/markd/rails/crm2_restyle/app/controllers/orders_controller.rb:45:in
> `processorder'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ba se.rb:1331:in
> `send'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ba se.rb:1331:in
> `perform_action_without_filters'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fi lters.rb:617:in
> `call_filters'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fi lters.rb:610:in
> `perform_action_without_benchmark'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/be nchmarking.rb:68:in
> `perform_action_without_rescue'
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/co re_ext/benchmark.rb:17:in
> `ms'
> /usr/local/lib/ruby/1.8/benchmark.rb:308:in `realtime'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/st ring_coercion.rb:25:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24: in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/pa rams_parser.rb:15:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/metal.rb:47:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/se ssion/cookie_store.rb:93:in
> `call'
> /home/markd/rails/crm2_restyle/app/middleware/flash_session_cookie_middlewa re.rb:55:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fa ilsafe.rb:26:in
> `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in
> `synchronize'
> /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'

happs74

未読、
2010/09/28 12:24:562010/09/28
To: Oracle enhanced adapter for ActiveRecord
Okay, i added this logging in ar base.rb

def create
logger.info("\n\n[AR base.rb]\n")
logger.info("SELF.ID:#{self.id}")
logger.info("TABLE_NAME:#{self.class.table_name}")

logger.info("Connection.prefetch_primary_key?:#{connection.prefetch_primary_key?
(self.class.table_name)}")
if self.id.nil? && connection.prefetch_primary_key?
(self.class.table_name)
logger.info("SEQ NAME:#{self.class.sequence_name}")
logger.info("TEST SEQ
GET:#{connection.next_sequence_value(self.class.sequence_name)}")
self.id =
connection.next_sequence_value(self.class.sequence_name)
end
....

Output in logger was:

[AR base.rb]
SELF.ID:
TABLE_NAME:subupgrade
Connection.prefetch_primary_key?:false




Sanity checked on db:

Connected.
SQL> select subupgrade_seq.nextval from dual;

NEXTVAL
----------
100010061

SQL>




Switch to enhanced adapter 1.2.4

Output in logger:

[AR base.rb]
SELF.ID:
TABLE_NAME:subupgrade
Connection.prefetch_primary_key?:true
SEQ NAME:subupgrade_seq
SQL (1.1ms) SELECT subupgrade_seq.NEXTVAL id FROM dual
TEST SEQ GET:100010063
CACHE (0.0ms) SELECT subupgrade_seq.NEXTVAL id FROM dual
Subupgrade Create (34.3ms) INSERT INTO subupgrade (tableid,
quantity, subupgradeid, subscriptionid, prodcode, tablename,
contactid, status) VALUES(100010028, 100, 100010063, 100010249,
'EASYE100BW000Y', 'WEBMAP', 100010000, 'ACTIVE')
SQL (0.6ms) SELECT trigger_name
FROM all_triggers
WHERE owner = 'ICRM'
AND trigger_name = 'SYSTEMCFG_PKT'
AND table_owner = 'ICRM'
AND table_name = 'SYSTEMCFG'
AND status = 'ENABLED'

Raimonds Simanovskis

未読、
2010/09/28 15:26:402010/09/28
To: Oracle enhanced adapter for ActiveRecord
Something is wrong with connection.prefetch_primary_key?
(self.class.table_name) returning false - it should return true unless
1) you don't have a primary key 2) or primary key is populated by
trigger.

Try to debug prefetch_primary_key? method in activerecord-
oracle_enhanced-adapter file lib/active_record/connection_adapters/
oracle_enhanced_adapter.rb to find out why it is returning false.

Raimonds

happs74

未読、
2010/09/28 21:20:342010/09/28
To: Oracle enhanced adapter for ActiveRecord
Should have thought to check but whoever added the subupgrade table
didn't add a primary key constraint and i noticed that the
columns_without_cache method has changed between

1.2.4
if has_primary_key_trigger?(table_name, owner, desc_table_name,
db_link)
@@do_not_prefetch_primary_key[table_name] = true
end


1.3.1
@@do_not_prefetch_primary_key[table_name] =
!has_primary_key?(table_name, owner, desc_table_name, db_link) ||
has_primary_key_trigger?(table_name, owner, desc_table_name,
db_link)

which would explain the problem.

Thanks for all your help on this Raimonds, it was greatly appreciated.
全員に返信
投稿者に返信
転送
新着メール 0 件