-->
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: Associations with composite keys in child - Limitation?
PostPosted: Thu Jan 06, 2005 6:40 pm 
Newbie

Joined: Thu Jan 06, 2005 6:27 pm
Posts: 10
I know people have reported the "Repeated column in mapping issue" earlier but I am not using the key-many-to-one element. My scenario is simple. I have a one-to-many between a department table and an employee table. I am using composite keys in employee table (dept_id, emp_id). I get the following error:

Repeated column in mapping for class model.Employee should be mapped with insert="false" update="false": dept_id

Following are the details:

Hibernate version: 2.1

Mapping documents:
<hibernate-mapping>

<class name="model.Dept" table="department">

<id name="deptId" column="dept_id" type="int" unsaved-value="0">
<generator class="assigned"/>
</id>

<property name="deptName" column="dept_name" type="string"/>


<set name="employees" outer-join="true" inverse="true" cascade="all">
<key>
<column name="dept_id"/>
</key>
<one-to-many class="model.Employee"/>
</set>

</class>

<class name="model.Employee" table="employee">

<composite-id>
<key-property name="deptId" column="dept_id" type="int"/>
<key-property name="empId" column="emp_id" type="int"/>
</composite-id>

<property name="empName" column="emp_name" type="string"/>

<many-to-one name="dept" class="model.Dept">
<column name="dept_id"/>
</many-to-one>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Repeated column in mapping for class model.Employee should be mapped with insert="false" update="false": dept_id
Name and version of the database you are using: Mysql 4.1
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

The limitations section of the reference (section 8.2) says "there is no way to map any association to multiple foreign keys". Can you please elaborate on this limitation? Does this mean that the employees collection cannot be inserted when I insert a department object? Is this the limitation I am hitting?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 07, 2005 7:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is not the appropriate reference.
You cannot set the same DB value twice in your object model. So if you set deptId in your composite PK, then you must set many-to-one as insert=false unpdate=false... or use key-many-to-one

_________________
Emmanuel


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.