Hi,
I am using Hibernate 2.1 and Sybase database.
We have a table called Program with the following columns
id
clientID
startDate
parentId
There are two objects mapped to this table as below
Program:
id
clientID
startDate
programGroup
ProgramGroup:
id
clientId
startDate
Note that the ProgramGroup is an attribute of the Program object. id and clientID are the composite ids for the both the objects. We proceeded with the following mapping
<class name="com.entity.Program" table="Program" dynamic-update="true" dynamic-insert="true">
<composite-id name="programPK" class="com.entity.ProgramPK" >
<key-property name="clientID" column="clientID" />
<key-property name="id" column="id"/>
</composite-id>
<property name="startDate" column="startDate"/>
<many-to-one name="parent" class="com.entity.ProgramGroup" cascade="all" outer-join="true">
<column name="parentID" />
</many-to-one>
</class>
<class name="com.entity.ProgramGroup" table="Program" dynamic-update="true" dynamic-insert="true">
<composite-id name="programGroupPK" class="com.entity.ProgramGroupPK" >
<key-property name="clientID" column="clientID" />
<key-property name="id" column="id"/>
</composite-id>
<property name="startDate" column="startDate"/>
</class>
net.sf.hibernate.MappingException: Foreign key (Program [parentID])) must have same number of columns as the referenced primary key (Program [clientID,id])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:649)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:743)
at com.test.ormapping.HibernateTestCase.<clinit>(HibernateTestCase.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at junit.framework.TestSuite.createTest(TestSuite.java:135)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:331)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:369)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
I know that clientID is missing in the many-to-one mapping. But my situation is that the clientID is also a part of the composite-id of the Program object. I cannot have the clientId in both the places. Please let me know if there are any workaround for this problem.
Any suggestion/help will be higly appreciated.
Thanks and Regards
|