-->
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: More than one relationship using the same join column
PostPosted: Mon Feb 15, 2010 1:31 am 
Newbie

Joined: Sun Mar 22, 2009 5:20 am
Posts: 6
I'm using a legacy database schema with composite keys. I have an entity with two relationships and one of the join columns is shared.

For example, Let's say i have a Student entity with two relationships Department and Course. Department uses dept_code column while Course uses dept_code and course_code colum. The domain model is such that a student might belong to a department and not opted for a course yet or both.

This is how the hibernate mapping looks like:

<hibernate-mapping>
<class name="Student" table="students">
<id column="id" name="id" type="integer">
<generator class="native"/>
</id>
<property column="name" name="name" type="string"/>

<many-to-one class="Department" name="department">
<column name="dept_code"/>
</many-to-one>

<many-to-one class="Course" name="course>
<column name="dept_code"/>
<column name="course_code"/>
</many-to-one>
</class>
</hibernate-mapping>

The problem is Hibernate does not allow this mapping unless one of the relationships is marked readonly using insert=false and update=false.

Is there a way to have both relationships as writable?


Top
 Profile  
 
 Post subject: Re: More than one relationship using the same join column
PostPosted: Mon Feb 15, 2010 11:00 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
sathish316 wrote:
<many-to-one class="Department" name="department">
<column name="dept_code"/>
</many-to-one>

<many-to-one class="Course" name="course>
<column name="dept_code"/>
<column name="course_code"/>
</many-to-one>


try this instead.

Code:
<many-to-one class="Department" name="department">
      <column name="dept_code"/>
    </many-to-one>

    <many-to-one class="Course" name="course" [b]not-found="ignore"[/b]>
      [b]<formula>dept_code</formula>[/b]
      <column name="course_code"/>
    </many-to-one>


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.