违反了完整性约束 - 未找到父键

时间:2015-01-05 11:46:40

标签: java hibernate java-ee

我正在尝试将提供者记录和OtherCountry记录插入到数据库中,我收到错误

java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (MTMMIS92E2.P_OTHER_CNTRY_FN1) violated - parent key not found

Provider.java中的代码

  

私人其他国家其他国家;

Provider.hbm.xml中的代码

<class name= "com.test.domain.Provider" 
       table="P_DTL_TB" dynamic-insert="true" dynamic-update="true" select-before-update="true">
  <id name="sysID" column="P_SYS_ID" type="java.lang.Long">
        <generator class="native">
            <param name="sequence">P_SYS_ID_SEQ</param>
        </generator>
    </id>
      <one-to-one name="otherCountry" class="com.test.domain.OtherCountry" fetch="select"   cascade="all" constrained="true"></one-to-one>

OtherCountry.hbm.xml中的代码

<class name="com.test.domain.OtherCountry"
    table="P_OTHER_CNTRY_TN" dynamic-insert="true" dynamic-update="true"
    select-before-update="true">

    <id name="sysId" type="java.lang.Long" column="P_SYS_ID">
        <generator class="foreign">
            <param name="property">provider</param>
        </generator>
    </id>

    <property name="otherCountryName" type="java.lang.String" column="P_OTHER_CNTRY_NAM"></property>

    <one-to-one name="provider" class="com.test.domain.Provider" constrained="true" lazy="proxy"></one-to-one>
</class>

保存代码

Provider provider = new Provider();
provider.setSysId(new Long(0));

OtherCountry otherCountry = new OtherCountry();

otherCountry.setOtherCountryName(primaryAppOC.getOtherCountryName());
otherCountry.setProvider(provider);

provider.setOtherCountry(otherCountry);

在保存时我收到错误

Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (MTMMIS92E2.P_OTHER_CNTRY_FN1) violated - parent key not found

where P_OTHER_CNTRY_FN1 is the Primary key for OtherCountry.

请帮我解决这个问题。

此致 Adarsh

0 个答案:

没有答案