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