-->
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 with one-to-many mapping with composite Key
PostPosted: Tue Sep 04, 2007 5:01 am 
Newbie

Joined: Thu May 18, 2006 6:36 am
Posts: 11
Location: Bangalore
Hi,

I am trying to create a one-to-many mapping between two of my classes, one in a view having a composite key and the other a normal table.

I am getting the following exception when the session factory is being created,

org.hibernate.MappingException: Foreign key (FKF327F4562EB74EE3:ACCOUNTS_CONTACTS_COLL_RPT [ACCOUNT_NO])) must have same number of columns as the referenced primary key (V_PYCIS_DWH_ACCT [INSTN_ID_N,INSTN_NM_C,TMPL_TYPE_LVL_1_C,TMPL_TYPE_LVL_2_C,TMPL_TYPE_LVL_3_C,DWS_ACCT_ID,CIBS_ACCT_NUM_N,QIMD_PORTF_NUM_C,CIBS_DISC_NM_C,CIBS_DISC_CODE_C,CIBS_SUBDISC_CODE_C,CIBS_SUBDISC_NM_C,CIBS_STRUC_CODE_C,QIMD_STRUC_CODE_C,IM_BRAND_CODE_C,ASAP_ACCT_NM_C,ASAP_ACCT_NUM_N])
Foreign key (FKF327F4562EB74EE3:ACCOUNTS_CONTACTS_COLL_RPT [ACCOUNT_NO])) must have same number of columns as the referenced primary key (V_PYCIS_DWH_ACCT [INSTN_ID_N,INSTN_NM_C,TMPL_TYPE_LVL_1_C,TMPL_TYPE_LVL_2_C,TMPL_TYPE_LVL_3_C,DWS_ACCT_ID,CIBS_ACCT_NUM_N,QIMD_PORTF_NUM_C,CIBS_DISC_NM_C,CIBS_DISC_CODE_C,CIBS_SUBDISC_CODE_C,CIBS_SUBDISC_NM_C,CIBS_STRUC_CODE_C,QIMD_STRUC_CODE_C,IM_BRAND_CODE_C,ASAP_ACCT_NM_C,ASAP_ACCT_NUM_N])

My mapping classes are defines as follows

VPycisDwhAcctId.hbm.xml
Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 3, 2007 5:14:09 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="com.pyramis.pcr.vo.VPycisDwhAcct" table="V_PYCIS_DWH_ACCT">
        <composite-id name="id" class="com.pyramis.pcr.vo.VPycisDwhAcctId">
            <key-property name="instnIdN" type="long">
                <column name="INSTN_ID_N" precision="12" scale="0" />
            </key-property>
            <key-property name="instnNmC" type="string">
                <column name="INSTN_NM_C" />
            </key-property>
            <key-property name="tmplTypeLvl1C" type="string">
                <column name="TMPL_TYPE_LVL_1_C" length="12" />
            </key-property>
            <key-property name="tmplTypeLvl2C" type="string">
                <column name="TMPL_TYPE_LVL_2_C" length="12" />
            </key-property>
            <key-property name="tmplTypeLvl3C" type="string">
                <column name="TMPL_TYPE_LVL_3_C" length="12" />
            </key-property>
            <key-property name="dwsAcctId" type="java.lang.Long">
                <column name="DWS_ACCT_ID" precision="12" scale="0" />
            </key-property>
            <key-property name="cibsAcctNumN" type="big_decimal">
                <column name="CIBS_ACCT_NUM_N" precision="22" scale="0" />
            </key-property>
            <key-property name="qimdPortfNumC" type="string">
                <column name="QIMD_PORTF_NUM_C" length="12" />
            </key-property>
            <key-property name="cibsDiscNmC" type="string">
                <column name="CIBS_DISC_NM_C" length="50" />
            </key-property>
            <key-property name="cibsDiscCodeC" type="string">
                <column name="CIBS_DISC_CODE_C" length="5" />
            </key-property>
            <key-property name="cibsSubdiscCodeC" type="string">
                <column name="CIBS_SUBDISC_CODE_C" length="5" />
            </key-property>
            <key-property name="cibsSubdiscNmC" type="string">
                <column name="CIBS_SUBDISC_NM_C" length="50" />
            </key-property>
            <key-property name="cibsStrucCodeC" type="string">
                <column name="CIBS_STRUC_CODE_C" length="5" />
            </key-property>
            <key-property name="qimdStrucCodeC" type="string">
                <column name="QIMD_STRUC_CODE_C" length="5" />
            </key-property>
            <key-property name="imBrandCodeC" type="string">
                <column name="IM_BRAND_CODE_C" length="4" />
            </key-property>
            <key-property name="asapAcctNmC" type="string">
                <column name="ASAP_ACCT_NM_C" length="50" />
            </key-property>
            <key-property name="asapAcctNumN" type="java.lang.Long">
                <column name="ASAP_ACCT_NUM_N" precision="15" scale="0" />
            </key-property>
        </composite-id>
       
        <set name="comments">
           <key column="ACCOUNT_NO" />
           <one-to-many class="com.pyramis.pcr.vo.AccountsContactsCollRpt"/>
        </set>
     
       
    </class>
</hibernate-mapping>



AccountsContactsCollRpt.hbm.xml
Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 3, 2007 5:18:19 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="com.pyramis.pcr.vo.AccountsContactsCollRpt" table="ACCOUNTS_CONTACTS_COLL_RPT" schema="REPORTS">
        <composite-id name="id" class="com.pyramis.pcr.vo.AccountsContactsCollRptId">
            <key-property name="accountNo" type="integer">
                <column name="ACCOUNT_NO" precision="8" scale="0" />
            </key-property>
            <key-property name="personCode" type="integer">
                <column name="PERSON_CODE" precision="8" scale="0" />
            </key-property>
            <key-property name="startDate" type="timestamp">
                <column name="START_DATE" length="7" />
            </key-property>
            <key-property name="reportCode" type="string">
                <column name="REPORT_CODE" length="8" />
            </key-property>
        </composite-id>
        <property name="feedDate" type="timestamp">
            <column name="FEED_DATE" length="7" not-null="true" />
        </property>
        <property name="endDate" type="timestamp">
            <column name="END_DATE" length="7" not-null="true" />
        </property>
        <property name="frequencyCode" type="string">
            <column name="FREQUENCY_CODE" length="5" />
        </property>
        <property name="frequencyName" type="string">
            <column name="FREQUENCY_NAME" length="50" />
        </property>
        <property name="distrMethodCode" type="string">
            <column name="DISTR_METHOD_CODE" length="5" />
        </property>
        <property name="distrMethodName" type="string">
            <column name="DISTR_METHOD_NAME" length="50" />
        </property>
        <property name="reportName" type="string">
            <column name="REPORT_NAME" length="50" />
        </property>
        <property name="ldrIdN" type="java.lang.Short">
            <column name="LDR_ID_N" precision="4" scale="0" />
        </property>
        <property name="ldDtD" type="timestamp">
            <column name="LD_DT_D" length="7" />
        </property>
        <property name="numOfCopies" type="java.lang.Long">
            <column name="NUM_OF_COPIES" precision="10" scale="0" />
        </property>
        <property name="outputMediaCode" type="string">
            <column name="OUTPUT_MEDIA_CODE" length="5" />
        </property>
        <property name="outputMediaName" type="string">
            <column name="OUTPUT_MEDIA_NAME" length="50" />
        </property>
        <property name="bindingMethodCode" type="string">
            <column name="BINDING_METHOD_CODE" length="5" />
        </property>
        <property name="bindingMethodName" type="string">
            <column name="BINDING_METHOD_NAME" length="50" />
        </property>
        <property name="packetCode" type="string">
            <column name="PACKET_CODE" length="14" />
        </property>
        <property name="packetName" type="string">
            <column name="PACKET_NAME" length="250" />
        </property>
        <property name="accountReportComments" type="string">
            <column name="ACCOUNT_REPORT_COMMENTS" length="1000" />
        </property>
        <property name="packetComments" type="string">
            <column name="PACKET_COMMENTS" length="1000" />
        </property>
    </class>
</hibernate-mapping>


How can i achieve this??

Thanks ,
Rohit


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 5:22 am 
Newbie

Joined: Tue Jul 31, 2007 8:37 am
Posts: 12
you have to duplicate the key-property as a normal property in the file AccountsContactsCollRpt.hbm.xml

Code:
<key-property name="accountNo" type="integer">
                <column name="ACCOUNT_NO" precision="8" scale="0" />
            </key-property>


add the following code (below the composite-key tags):

Code:
<property name="accountNo" insert="false" update="false" column="ACCOUNT_NO"/>


Now it should be possible to use this part of the composite key as a foreign key of the other table.

please dont forget to vote, if it helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 5:57 am 
Newbie

Joined: Thu May 18, 2006 6:36 am
Posts: 11
Location: Bangalore
Hi,

I tried what u said , but i still seem to be getting the same error

Quote:
org.hibernate.MappingException: Foreign key (FKF327F4562EB74EE3:ACCOUNTS_CONTACTS_COLL_RPT [ACCOUNT_NO])) must have same number of columns as the referenced primary key (V_PYCIS_DWH_ACCT [INSTN_ID_N,INSTN_NM_C,TMPL_TYPE_LVL_1_C,TMPL_TYPE_LVL_2_C,TMPL_TYPE_LVL_3_C,DWS_ACCT_ID,CIBS_ACCT_NUM_N,QIMD_PORTF_NUM_C,CIBS_DISC_NM_C,CIBS_DISC_CODE_C,CIBS_SUBDISC_CODE_C,CIBS_SUBDISC_NM_C,CIBS_STRUC_CODE_C,QIMD_STRUC_CODE_C,IM_BRAND_CODE_C,ASAP_ACCT_NM_C,ASAP_ACCT_NUM_N])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1187)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1094)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter$1.execute(ConsoleConfigurationWorkbenchAdapter.java:43)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:89)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:39)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:88)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:94)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:196)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!SUBENTRY 2 org.hibernate.eclipse.console 4 150 2007-09-04 15:23:39.168
!MESSAGE org.hibernate.MappingException: Foreign key (FKF327F4562EB74EE3:ACCOUNTS_CONTACTS_COLL_RPT [ACCOUNT_NO])) must have same number of columns as the referenced primary key (V_PYCIS_DWH_ACCT [INSTN_ID_N,INSTN_NM_C,TMPL_TYPE_LVL_1_C,TMPL_TYPE_LVL_2_C,TMPL_TYPE_LVL_3_C,DWS_ACCT_ID,CIBS_ACCT_NUM_N,QIMD_PORTF_NUM_C,CIBS_DISC_NM_C,CIBS_DISC_CODE_C,CIBS_SUBDISC_CODE_C,CIBS_SUBDISC_NM_C,CIBS_STRUC_CODE_C,QIMD_STRUC_CODE_C,IM_BRAND_CODE_C,ASAP_ACCT_NM_C,ASAP_ACCT_NUM_N])
!STACK 0
org.hibernate.MappingException: Foreign key (FKF327F4562EB74EE3:ACCOUNTS_CONTACTS_COLL_RPT [ACCOUNT_NO])) must have same number of columns as the referenced primary key (V_PYCIS_DWH_ACCT [INSTN_ID_N,INSTN_NM_C,TMPL_TYPE_LVL_1_C,TMPL_TYPE_LVL_2_C,TMPL_TYPE_LVL_3_C,DWS_ACCT_ID,CIBS_ACCT_NUM_N,QIMD_PORTF_NUM_C,CIBS_DISC_NM_C,CIBS_DISC_CODE_C,CIBS_SUBDISC_CODE_C,CIBS_SUBDISC_NM_C,CIBS_STRUC_CODE_C,QIMD_STRUC_CODE_C,IM_BRAND_CODE_C,ASAP_ACCT_NM_C,ASAP_ACCT_NUM_N])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1187)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1094)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter$1.execute(ConsoleConfigurationWorkbenchAdapter.java:43)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:89)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:39)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:88)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:94)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:196)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


Thanks,
Rohit


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 6:16 am 
Newbie

Joined: Tue Jul 31, 2007 8:37 am
Posts: 12
ok, its perhaps not necessary to duplicate the key.

Try to change the key-property in the set mapping like:

Code:
<set ....>
  <key>
  <column name="ACCOUNT_NO"/>
  <column name="PERSON_CODE"/>
  .... and so on
  </key>
</set>


I cant really say, if it works, because i just have no DB to test.
But give it a try...

If not, then i can't help. sorry.


Top
 Profile  
 
 Post subject: I have a similiar problem...
PostPosted: Thu Sep 13, 2007 5:07 am 
Newbie

Joined: Thu Sep 13, 2007 4:55 am
Posts: 4
...and use the given methode by
Code:
<set ..
    <key>
       <column name="fk1"/>
       <column name="fk2/>
    </key>
   <one-to-many ... />
</set>

but it only possible if you set the id to :
Code:
<composite-id>
   <key-property name=foreignKey1 column="fk1" />
   <key-property name=foreignKey2 column="fk2" />
</composite-id>


and the target table has three primary keys. but I get everytime only one record.

Somebody any ideas?[/code]


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.