-->
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.  [ 2 posts ] 
Author Message
 Post subject: Composite id mapping problem
PostPosted: Wed Jul 04, 2007 6:52 am 
Newbie

Joined: Mon Jun 18, 2007 2:29 am
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1

Hello all,

I'm using hibernate 3.1 and generated all the mapping documents with Ecllipse IDE. I'm struggling to make the associations with multimple tables with composite ids.

I've two tables Mdl and Mat to be connected using MTBKOD .

The .hbm files are the following...

Mapping documents:

Mat.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Mapping file autogenerated by MyEclipse - Hibernate Tools -->

<hibernate-mapping>

<class name="com.DAO.orders.Mat" table="mat" catalog="pao">

<composite-id>

<key-property name="mtbkod" type="java.lang.String">

<column name="MTBKOD" length="6" />

</key-property>

<key-property name="matrngnum" type="java.lang.Integer">

<column name="MATRNGNUM" />

</key-property>

</composite-id>

<property name="mabnum" type="java.lang.Integer">

<column name="MABNUM" />

</property>

<property name="matmmt" type="java.lang.Short">

<column name="MATMMT" />

</property>

<property name="matnum" type="java.lang.Integer">

<column name="MATNUM" />

</property>

<property name="matoms" type="java.lang.String">

<column name="MATOMS" length="25" />

</property>

<many-to-one name="model" class="com.DAO.model.Mdl"

insert="false" update="false">

<column name="MTBKOD"/>

</many-to-one>


</class>

</hibernate-mapping>

============================================================================

Mdl.hbm.xml

<hibernate-mapping>

<class name="com.DAO.model.Mdl" table="mdl" catalog="pao">

<composite-id name="id" class="com.DAO.model.MdlId">

<key-property name="mdlkod" type="java.lang.String">

<column name="MDLKOD" length="10" />

</key-property>

<key-property name="mdlvar" type="java.lang.String">

<column name="MDLVAR" length="2" />

</key-property>

<key-property name="mtbkod" type="java.lang.String">

<column name="MTBKOD" length="6" />

</key-property>

</composite-id>

<property name="btwkod" type="java.lang.String">

<column name="BTWKOD" length="2" />

</property>

<property name="cbsnum" type="java.lang.Integer">

<column name="CBSNUM" />

</property>

.(some more properties.....)

.......................

........................

<set name="mtbDetails" inverse="true">

<key column="mtbkod"/>

<one-to-many class="com.DAO.orders.Mat"/>

</set>


</class>

</hibernate-mapping>


=========================================================================

I'm getting the following error...

org.hibernate.MappingException: Foreign key (FK1A560478C1E2C:mat [mtbkod])) must
have same number of columns as the referenced primary key (mdl [MDLKOD,MDLVAR,M
TBKOD])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configur
ation.java:1145)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:
1052)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java)

===========================================================================

Since I'm a beginner I'm not getting how to avoid this error.Can you please help me to sort out this problem ?



Thanks and regards,
Prasanth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 13, 2007 5:30 am 
Newbie

Joined: Thu Sep 13, 2007 4:55 am
Posts: 4
Hibernate doesn't allow to specify a set with a different number of keys as the given hibernate class.

if you have specify:
Code:
<composite-id..>
  <key-property ...>
  <key-property ...>
</composite-id>

you must write down:
Code:
<set ..>
  <key>
     <column name="">
     <column name="">
  </key>
</set>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.