0

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

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

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

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 的当前版本。

4

0 回答 0