Hey folks, I've a very simple ruby file as described as provided below. When I run the file the indication I get back from the .save method is that the notified attribute change has been saved and yet when I retrieve the row again straight away after the notified value hasn't changed and when I look at the db sure enough it hasn't changed. I'm running jruby RC3 ActiveRecord-JDBC 0.3.2 activerecord-1.15.3 activesupport-1.4.2 Has anyone any idea why this might be or how I can check to see if my connection has autocommit enabled from within jruby? Thanks Mark. require 'java' require 'rubygems' gem 'ActiveRecord-JDBC' require 'jdbc_adapter' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => "jdbc", :driver => 'oracle.jdbc.driver.OracleDriver', :url => "jdbc:oracle:thin:@mydbservver:1521:mydb", :username => "my_username", :password => "my_pass") class Alert < ActiveRecord::Base set_primary_key "ALERT_ID" def <=>(other) alert_id <=> other.alert_id end def to_s "Alert Id:=" + alert_id.to_s + ", parent_id := " + parent_id.to_s + ", message := " + message.to_s end end if __FILE__ == $0 alert = Alert.find(312) alert.notified = 'Y' puts alert if alert.save == false then raise "Error Message" end alert2 = Alert.find(312) puts alert2.notified end
on 2007-06-13 16:04
on 2007-06-13 16:14
Here's the DDL for the table, sequence and trigger --Table create table ALERTS ( alert_id number PRIMARY KEY , parent_id number, creation date NOT NULL, message varchar(100) NOT NULL, throwable varchar(3000), severity_id number CHECK ( severity_id IN (10000, 20000, 30000, 40000, 50000)) NOT NULL, severity_status varchar(20) CHECK (severity_status IN ('DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL')) NOT NULL, notified CHAR(1) DEFAULT ('N') CHECK (notified IN ( 'Y', 'N' )) , trace_user varchar(20), trace_session varchar(50), CONSTRAINT fk_alert FOREIGN KEY (parent_id) REFERENCES alerts(alert_id) ); --Sequence create sequence ALERT_SEQ start with 1 increment by 1 nomaxvalue; -- Trigger CREATE OR REPLACE TRIGGER STAGING_OWNER.ALERT_TRIGGER BEFORE INSERT ON STAGING_OWNER.ALERTS FOR EACH ROW begin select ALERT_SEQ.nextval into :new.alert_id from dual; end;
on 2007-06-13 16:39
On 6/13/07, Mark Gargan <firstname.lastname@example.org> wrote: > if alert.save == false then > raise "Error Message" > end No need for that construct; the save! method will raise an error if the save fails. Replace the above with: alert.save!
on 2007-06-13 16:44
Hey Bob, Thanks for getting back to me. I tried that earlier but to no avail. I still get the same result. Any idea how i find if autocommit is on via the connection in jruby? Thanks, Mark.
on 2007-06-13 18:08
I've since successfully performed the jruby ActiveRecord-JDBC found here. http://www.ociweb.com/mark/programming/ActiveRecord.html using the exact same connection specifications as in my example and it works fine. Tables are on the same database and everything so I think I can rule out that it's an oracle problem. Is that presumptuous? I can perform updates to my alerts table by getting hte connection and calling the update method with some SQL but this isn't the way I was hoping to develop it. Any ideas folks? Thanks, Mark
on 2007-06-14 12:50
The folks, Had to resort to querying the V$SQL statements at the oracle DB. Does anyone know how to output the SQL generated by ActiveRecord-JDBC? Would've made life a little easier. Anyways it turns out the problem was in the line in my Alert model, set_primary_key "ALERT_ID" ALERT_ID is indeed the primary key of the table, however, the attribute name in the Alert object is lowercase, alert_id. Because of that update sql was being appended with 'WHERE ALERT_ID is NULL' sure enough none of the records have and alert_id of null as its the primary key. Thanks, Mark.