facebook

Foreign key Exception have the same number of columns

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #288637 Reply

    rsvedula
    Member

    I am a beginner and started creating some mapping using hibernate mapping generator, but started getting an exception

    “Foreign Key(batch_job_Dependency)[ID_DEPENDANT_BATCH] must have the same number of columns as the referenced primary key
    (Batch_job)[ID_BATCH,ID_BATCH_JOB]”

    Could anyone please help me in fixing this problem, I would very much appreciate your help

    There are 2 tables

    create table “BATCH_JOB_DEPENDENCY”(
    “ID_DEPENDANT_BATCH” NUMBER not null,
    “ID_DEPENDANT_BATCH_JOB” NUMBER not null,
    “ID_BATCH” NUMBER not null,
    “ID_BATCH_JOB” NUMBER not null,
    constraint “PK_BATCH_JOB_DEPENDENCY” primary key (“ID_DEPENDANT_BATCH”,”ID_DEPENDANT_BATCH_JOB”,”ID_BATCH”,”ID_BATCH_JOB”)
    );

    alter table “BATCH_JOB_DEPENDENCY”
    add constraint “FK_MATCH_JOB_DEPENDENCY_01”
    foreign key (“ID_DEPENDANT_BATCH”,”ID_DEPENDANT_BATCH_JOB”)
    references “BATCH_JOB”(“ID_BATCH”,”ID_BATCH_JOB”);
    alter table “BATCH_JOB_DEPENDENCY”
    add constraint “FK_MATCH_JOB_DEPENDENCY_02”
    foreign key (“ID_BATCH”,”ID_BATCH_JOB”)
    references “BATCH_JOB”(“ID_BATCH”,”ID_BATCH_JOB”);
    create unique index “PK_BATCH_JOB_DEPENDENCY” on “BATCH_JOB_DEPENDENCY”(“ID_BATCH”,”ID_BATCH_JOB”,”ID_DEPENDANT_BATCH”,”ID_DEPENDANT_BATCH_JOB”);

    create table “BATCH_JOB”(
    “ID_BATCH_JOB” NUMBER not null,
    “JOB_NAME” VARCHAR2(30) not null,
    “JOB_DESCRIPTION” VARCHAR2(200),
    “JOB_ORDER” NUMBER not null,
    “JOB_STATUS” VARCHAR2(1) default ‘E’ not null,
    “ID_BATCH” NUMBER not null,
    “JOB_NUMBER” NUMBER not null,
    constraint “PK_BATCH_JOB” primary key (“ID_BATCH_JOB”,”ID_BATCH”)
    );

    alter table “BATCH_JOB”
    add constraint “FK_BATCH_JOB_01”
    foreign key (“ID_BATCH”)
    references “BATCH”(“ID_BATCH”);
    create unique index “IX_BATCH_JOB_01” on “BATCH_JOB”(“ID_BATCH”,”ID_BATCH_JOB”);

    create table “BATCH”(
    “ID_BATCH” NUMBER(8) not null,
    “NAME_BATCH” VARCHAR2(40) not null,
    “AD_FREQUENCY” VARCHAR2(30),
    “CMT” VARCHAR2(2000),
    constraint “PK_BATCH” primary key (“ID_BATCH”)
    );

    create unique index “IX_BATCH_01” on “BATCH”(“ID_BATCH”);

    These are the two mappings

    <hibernate-mapping>
    <class name=”hhsc.medicaid.ma.pps.bo.BatchJob” table=”BATCH_JOB” schema=”MA_DEV”>
    <composite-id name=”id” class=”hhsc.medicaid.ma.pps.bo.BatchJobId”>
    <key-property name=”idBatch” type=”java.lang.Long”>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ />
    </key-property>
    <key-property name=”idBatchJob” type=”java.lang.Long”>
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ />
    </key-property>
    </composite-id>
    <many-to-one name=”batch” class=”hhsc.medicaid.ma.pps.bo.Batch” update=”false” insert=”false” fetch=”select”>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    </many-to-one>
    <property name=”jobName” type=”java.lang.String”>
    <column name=”JOB_NAME” length=”30″ not-null=”true” />
    </property>
    <property name=”jobDescription” type=”java.lang.String”>
    <column name=”JOB_DESCRIPTION” length=”200″ />
    </property>
    <property name=”jobOrder” type=”java.lang.Long”>
    <column name=”JOB_ORDER” precision=”22″ scale=”0″ not-null=”true” />
    </property>
    <property name=”jobStatus” type=”java.lang.String”>
    <column name=”JOB_STATUS” length=”1″ not-null=”true”>
    <comment>E = Enabled, D = Disabled</comment>
    </column>
    </property>
    <property name=”jobNumber” type=”java.lang.Long”>
    <column name=”JOB_NUMBER” precision=”22″ scale=”0″ not-null=”true” />
    </property>
    <set name=”batchJobRuns” inverse=”true”>
    <key>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ not-null=”true” />
    </key>
    <one-to-many class=”hhsc.medicaid.ma.pps.bo.BatchJobRun” />
    </set>
    <set name=”batchJobSteps” inverse=”true”>
    <key>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ not-null=”true” />
    </key>
    <one-to-many class=”hhsc.medicaid.ma.pps.bo.BatchJobStep” />
    </set>
    <set name=”batchJobsForFkMatchJobDependency02″ inverse=”true” table=”BATCH_JOB_DEPENDENCY” schema=”MA_DEV”>
    <key>
    <column name=”ID_DEPENDANT_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    <column name=”ID_DEPENDANT_BATCH_JOB” precision=”22″ scale=”0″ not-null=”true” />
    </key>
    <many-to-many entity-name=”hhsc.medicaid.ma.pps.bo.BatchJob”>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    </many-to-many>
    </set>
    <set name=”batchJobsForFkMatchJobDependency01″ table=”BATCH_JOB_DEPENDENCY” schema=”MA_DEV”>
    <key>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ not-null=”true” />
    </key>
    <many-to-many entity-name=”hhsc.medicaid.ma.pps.bo.BatchJob”>
    <column name=”ID_DEPENDANT_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    </many-to-many>
    </set>
    <set name=”batchFtps” inverse=”true”>
    <key>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ not-null=”true” />
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ />
    </key>
    <one-to-many class=”hhsc.medicaid.ma.pps.bo.BatchFtp” />
    </set>
    </class>
    </hibernate-mapping>

    <hibernate-mapping>
    <class name=”hhsc.medicaid.ma.pps.bo.BatchJobDependency” table=”BATCH_JOB_DEPENDENCY” schema=”MA_DEV”>
    <composite-id name=”id” class=”hhsc.medicaid.ma.pps.bo.BatchJobDependencyId”>
    <key-property name=”idBatch” type=”java.lang.Long”>
    <column name=”ID_BATCH” precision=”22″ scale=”0″ />
    </key-property>
    <key-property name=”idBatchJob” type=”java.lang.Long”>
    <column name=”ID_BATCH_JOB” precision=”22″ scale=”0″ />
    </key-property>
    <key-property name=”idDependantBatch” type=”java.lang.Long”>
    <column name=”ID_DEPENDANT_BATCH” precision=”22″ scale=”0″ />
    </key-property>
    <key-property name=”idDependantBatchJob” type=”java.lang.Long”>
    <column name=”ID_DEPENDANT_BATCH_JOB” precision=”22″ scale=”0″ />
    </key-property>
    </composite-id>
    </class>
    </hibernate-mapping>

    #288677 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Foreign key Exception have the same number of columns

You must be logged in to post in the forum log in