-->
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.  [ 3 posts ] 
Author Message
 Post subject: Same table with 2 mappings
PostPosted: Thu Mar 11, 2004 6:54 am 
Newbie

Joined: Tue Dec 02, 2003 9:12 am
Posts: 7
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 2:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
That's the first time I've seen such weird stuff.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 2:25 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
<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.Program" cascade="all" outer-join="true">
<column name="parentID" />
... //respect composite id
</many-to-one>
</class>


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