-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem w/ FK Mapping
PostPosted: Wed Sep 10, 2003 9:21 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
I can't figure out what is wrong with my mappings. I'm getting the following Exception:
Code:
Exception in thread "main" net.sf.hibernate.MappingException: Foreign key must have same number of columns as referenced primary key
Start server side stack trace:
net.sf.hibernate.MappingException: Foreign key must have same number of columns as referenced primary key
        at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:33)
        at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:523)
        at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:623)

last entries in debug log:
Code:
...
09:09:42,808  INFO Configuration:503 - processing foreign key constraints
... (other FKs process OK)
09:09:42,818 DEBUG Configuration:513 - resolving reference to class: com.*****.cc.objectlib.schedule.ScheduleState


Mapping for ScheduleState:
Code:
  <class
      name="com.*****.cc.objectlib.schedule.ScheduleState"
      table="SCHEDULE">
    <id name="id" type="java.lang.Long">
      <column name="SCHEDULE_ID"/>
      <generator class="sequence">
        <param name="sequence">schedule_seq</param>
      </generator>
    </id>
<!-- properties deleted -->
    <!-- associations -->
    <!-- bi-directional many-to-one association to ScheduleSnapshotState -->
    <many-to-one
        name="scheduleSnapshotState"
        class="com.*****.cc.objectlib.schedule.ScheduleSnapshotState"
        not-null="true"
        update="false"
        insert="false">
      <column name="SCHEDULE_SNAPSHOT_ID"/>
    </many-to-one>
    <!-- bi-directional one-to-many association to TariffScheduleState -->
    <set
        name="tariffScheduleStates"
        lazy="true"
        inverse="true"
        cascade="all-delete-orphan">
      <key>
        <column name="SCHEDULE_SNAPSHOT_ID"/>
        <column name="SCHEDULE_ID"/>
      </key>
      <one-to-many
          class="com.*****.cc.objectlib.tariff.TariffScheduleState"/>
    </set>
  </class>

Mapping for ScheduleSnapshotState:
Code:
  <class
      name="com.*****.cc.objectlib.schedule.ScheduleSnapshotState"
      table="SCHEDULE_SNAPSHOT">
    <id name="id" type="java.lang.Long">
      <column name="SCHEDULE_SNAPSHOT_ID"/>
      <generator class="sequence">
        <param name="sequence">schedule_snapshot_seq</param>
      </generator>
    </id>
<!-- properties deleted -->
   <!-- associations -->
    <!-- bi-directional one-to-many association to ScheduleState -->
    <set
        name="scheduleStates"
        lazy="true"
        inverse="true"
        cascade="all-delete-orphan">
      <key>
        <column name="SCHEDULE_SNAPSHOT_ID"/>
      </key>
      <one-to-many
          class="com.*****.cc.objectlib.schedule.ScheduleState"/>
    </set>
  </class>

Mapping for TariffScheduleState:
Code:
  <class
      name="com.*****.cc.objectlib.tariff.TariffScheduleState"
      table="TARIFF_SCHEDULE">
    <id name="id" type="java.lang.Long">
      <column name="SEQ_ID"/>
      <generator class="sequence">
        <param name="sequence">tariff_schedule_seq</param>
      </generator>
    </id>
<!-- properties deleted -->
    <!-- associations -->
    <!-- bi-directional many-to-one association to ScheduleState -->
    <many-to-one
        name="scheduleState"
        class="com.*****.cc.objectlib.schedule.ScheduleState"
        not-null="true"
        update="false"
        insert="false">
      <column name="SCHEDULE_SNAPSHOT_ID"/>
      <column name="SCHEDULE_ID"/>
    </many-to-one>
    <!-- bi-directional many-to-one association to TariffState -->
    <many-to-one
        name="tariffState"
        class="com.*****.cc.objectlib.tariff.TariffState"
        not-null="true"
        update="false"
        insert="false">
      <column name="TARIFF_ID"/>
    </many-to-one>
  </class>


Am I right to assume that the problem is in ScheduleState since that is the last entry in the debug log? If that is the case, then I can't find the problem. It looks to me like all both sides of the associations match up.

Any help would be appreciated. I'm using 2.0.3.

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 9:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
<many-to-one
        name="scheduleState"
        class="com.*****.cc.objectlib.schedule.ScheduleState"
        not-null="true"
        update="false"
        insert="false">
      <column name="SCHEDULE_SNAPSHOT_ID"/>
      <column name="SCHEDULE_ID"/>
    </many-to-one>



ScheduleState does not have a composite id.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 10:29 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 1:02 pm
Posts: 34
Location: Akron, OH
That did it. Thanks. I just converted everything from composite ids.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 5:50 pm 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
Iam getting simillar problem...

My Problem looks Like this

Quote:
%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.MappingException: Foreign key (CSW_CHILD_1 [COUNTY_CD])) must have same number of columns as the referenced primary key (CSW_CASE_PARENT_1 [CASE_ID,COUNTY_CD])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:67)
at net.sf.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:696)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:671)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
at us.ny.state.otda.dcse.commons.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:59)
at us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.ParentPersister.getParentRole(ParentPersister.java:37)
at us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.ParentPersister.main(ParentPersister.java:24)
java.lang.NullPointerException
at us.ny.state.otda.dcse.commons.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:68)
at us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.ParentPersister.getParentRole(ParentPersister.java:37)
at us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.ParentPersister.main(ParentPersister.java:24)




My CswCaseParent1.hbm.xml looks like this

Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Wed Sep 07 16:56:45 EDT 2005                         -->
<hibernate-mapping package="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer">

    <class name="CswCaseParent1" table="CSW_CASE_PARENT_1">
        <composite-id name="id" class="CswCaseParent1Key">
            <key-property name="caseId" column="CASE_ID" type="java.lang.String"/>
            <key-property name="countyCd" column="COUNTY_CD" type="java.lang.String"/>
        </composite-id>

        <property name="clientSsnId" column="CLIENT_SSN_ID" type="java.lang.String" />
        <property name="pinId" column="PIN_ID" type="java.lang.String"  not-null="true" />
        <property name="clientPinId" column="CLIENT_PIN_ID" type="java.lang.String"  not-null="true" />
        <property name="clientNm" column="CLIENT_NM" type="java.lang.String" />
        <property name="netDueAmt" column="NET_DUE_AMT" type="java.lang.Double"  not-null="true" />
        <property name="respondentBirthDt" column="RESPONDENT_BIRTH_DT" type="java.util.Date" />
        <property name="respondentAddressTypeCd" column="RESPONDENT_ADDRESS_TYPE_CD" type="java.lang.String" />
        <property name="respondentUpdateSsnId" column="RESPONDENT_UPDATE_SSN_ID" type="java.lang.String" />
        <property name="paymentFromDt" column="PAYMENT_FROM_DT" type="java.util.Date"  not-null="true" />
        <property name="paymentToDt" column="PAYMENT_TO_DT" type="java.util.Date"  not-null="true" />
        <property name="respondentSsnId" column="RESPONDENT_SSN_ID" type="java.lang.String" />
        <property name="respondentPinId" column="RESPONDENT_PIN_ID" type="java.lang.String"  not-null="true" />
        <property name="respondentNm" column="RESPONDENT_NM" type="java.lang.String" />
        <property name="createDt" column="CREATE_DT" type="java.util.Date"  not-null="true" />
        <property name="modifyDt" column="MODIFY_DT" type="java.util.Date" />
        <property name="controlCycleNbr" column="CONTROL_CYCLE_NBR" type="java.lang.Integer"  not-null="true" />
        <property name="ncpUpdateDt" column="NCP_UPDATE_DT" type="java.util.Date" />

        <set name="cswChild1Set" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswChild1"/>
        </set>

        <set name="cswChild11Set" inverse="true">
            <key column="COUNTY_CD"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswChild1"/>
        </set>

        <set name="cswDisbursement1Set" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswDisbursement1"/>
        </set>

        <set name="cswDisbursement11Set" inverse="true">
            <key column="COUNTY_CD"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswDisbursement1"/>
        </set>

        <set name="cswEmployer1Set" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswEmployer1"/>
        </set>

        <set name="cswEmployer11Set" inverse="true">
            <key column="COUNTY_CD"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswEmployer1"/>
        </set>

        <set name="cswMedicalInsurance1Set" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswMedicalInsurance1"/>
        </set>

        <set name="cswMedicalInsurance11Set" inverse="true">
            <key column="COUNTY_CD"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswMedicalInsurance1"/>
        </set>

        <set name="cswPayment1Set" inverse="true">
            <key column="CASE_ID"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswPayment1"/>
        </set>

        <set name="cswPayment11Set" inverse="true">
            <key column="COUNTY_CD"/>
            <one-to-many class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswPayment1"/>
        </set>
    </class>
   
</hibernate-mapping>



My CswChild1.hbm.xml looks like this

Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Wed Sep 07 17:14:09 EDT 2005                         -->
<hibernate-mapping package="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer">

    <class name="CswChild1" table="CSW_CHILD_1">
        <id name="childId" column="CHILD_ID" type="java.lang.Long">
            <generator class="hilo"/>
        </id>

        <property name="childFirstNm" column="CHILD_FIRST_NM" type="java.lang.String" />
        <property name="childMiNm" column="CHILD_MI_NM" type="java.lang.String" />
        <property name="childLastNm" column="CHILD_LAST_NM" type="java.lang.String" />
        <property name="childBirthDt" column="CHILD_BIRTH_DT" type="java.util.Date" />
        <property name="createDt" column="CREATE_DT" type="java.util.Date"  not-null="true" />
        <property name="modifyDt" column="MODIFY_DT" type="java.util.Date" />
        <property name="medicalInsuranceId" column="MEDICAL_INSURANCE_ID" type="java.lang.Long" />

        <many-to-one name="cswCaseParent1" column="CASE_ID" class="CswCaseParent1"  not-null="true" />

        <many-to-one name="cswCaseParent11" column="COUNTY_CD" class="CswCaseParent1"  not-null="true" />
    </class>
   
</hibernate-mapping>



Any Sort Of Help is much appreciable...

THanks In Advance

JD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 6:18 pm 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
I Solved this By modifying CswChild1.hbm.xml like this


Code:
        <many-to-one

           name="cswCaseParent1"
           class="us.ny.state.otda.dcse.viewpaymentsdisb.datatransfer.CswCaseParent1" 
           not-null="true"
           update="false"
           insert="false">
         <column name="CASE_ID"/>           
         <column name="COUNTY_CD"/>

    </many-to-one>


But iiam getting another problem

Quote:
%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.MappingException: collection foreign key mapping has wrong number of columns: *****.viewpaymentsdisb.datatransfer.CswCaseParent1.cswPayment11Set type: *****.datatransfer.CswCaseParent1Key


JD


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.