Coldfusion ORM Composite键未更新

时间:2013-03-27 00:50:31

标签: orm coldfusion coldfusion-9

我有一个我正在使用的旧数据库,只能进行有限的更改。这是我有一个表,其中包含复合键列reportnum和后缀的问题。我已将其设置为可以触发和序列正确设置值。因此,当我使用model.new()插入一个新值时,model.save()会正确地将值保存到数据库中,但问题是当我查看模型中的值时,reportnum和suffix是空字符串。

我尝试创建一个新的主键并将旧键转换为索引,但这会破坏与其他模型的关系。

寻找有关如何处理此问题的建议。谢谢。这是我如何制作触发器的链接。  Oracle PL/SQL Trigger Error

ORM模特:

component entityName="report" persistent="true" extends="coldbox.system.orm.hibernate.ActiveEntity" table="REPORTS" schema="myschema" {
    property name="reportnum" fieldtype="id" ; 
    property name="suffix" fieldtype="id" ; 
    property name="status"; 

    //Plus other properties...

    property name="parcels" 
        fieldtype="one-to-many" 
        type="array" 
        cfc="parcel" 
        singularname="parcel" 
        fkcolumn="reportnum,suffix" 
        column="reportnum,suffix"
            cascade="save-update";
}

component entityName="parcel" persistent="true" extends="coldbox.system.orm.hibernate.ActiveEntity" table="PARCELS" schema="myschema" {
    property name="parcel_id" column="parcelid" fieldtype="id" generator="sequence" sequence="myschema.seq1_parcels";
    property name="parcelnum";
    property name="reportnum";
    property name="suffix";
    //Plus other properties...
}

表:

CREATE TABLE reports(
    REPORTNUM      NUMBER(11),
    SUFFIX         NUMBER(11),
    STATUS         VARCHAR2(8),
;

ALTER TABLE REPORTS ADD ( CONSTRAINT PK_REPORTS PRIMARY KEY (REPORTNUM, SUFFIX));

CREATE SEQUENCE SEQ1_REPORTS MAXVALUE 1E28 START WITH 1;

CREATE OR REPLACE TRIGGER "TRG1_REPORTs" BEFORE INSERT ON
myschema.REPORTS FOR EACH ROW
BEGIN
    IF coalesce( :NEW.reportnum, -1 ) = -1 THEN
        SELECT myschema.seq1_REPORTs.NEXTVAL INTO :NEW.reportnum FROM dual;
        :NEW.SUFFIX := 0;
    elsif coalesce(:NEW.suffix,-1) = -1 then
        --If only a report number is given make the suffix 1 larger then the max found.
        SELECT MAX(suffix)+1
        INTO :NEW.suffix FROM myschema.REPORTS WHERE reportnum = :NEW.reportnum;
    END IF;
END;

/

CREATE OR REPLACE TRIGGER "TRG2_REPORTs" BEFORE update ON
myschema.REPORTS FOR EACH ROW
BEGIN
    IF coalesce( :OLD.REPORTid, -1 ) = -1 THEN
        SELECT myschema.seq2_REPORTs.NEXTVAL INTO :NEW.REPORTid FROM dual;
    END IF;
END;

/

CREATE OR REPLACE TRIGGER TRG1_REPORTs" BEFORE INSERT ON
myschema.REPORTS FOR EACH ROW
BEGIN
    IF coalesce( :NEW.reportnum, -1 ) = -1 THEN
        SELECT myschema.seq2_REPORTs.NEXTVAL INTO :NEW.reportnum FROM dual;
        :NEW.SUFFIX := 0;
    elsif coalesce(:NEW.suffix,-1) = -1 then
        --If only a report number is given make the suffix 1 larger then the max found.
        SELECT MAX(suffix)+1
        INTO :NEW.suffix FROM myschema.REPORTS WHERE reportnum = :NEW.reportnum;
    END IF;
END;

/


CREATE TABLE PARCELS (
    PARCELID       NUMBER(11) NOT NULL,
    PARCELNUM      NUMBER(11),
    REPORTNUM      NUMBER(11) DEFAULT 0,
    SUFFIX         NUMBER(11) DEFAULT 0,
    --Plus other properties...
;

ALTER TABLE PARCELS ADD ( CONSTRAINT PK_PARCELS PRIMARY KEY (PARCELID));

CREATE OR REPLACE TRIGGER "trg1_parcels" BEFORE INSERT ON
myschema.parcels FOR EACH ROW
BEGIN
    IF coalesce( :NEW.parcelid, -1 ) = -1  THEN
        SELECT myschema.seq1_parcels.NEXTVAL INTO :NEW.parcelid FROM DUAL;  
    END IF;
END;

/

Oracle 11,&当前版本的Coldfusion 9。

0 个答案:

没有答案