-->
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.  [ 4 posts ] 
Author Message
 Post subject: A Basic Quesion on Mapping relationships
PostPosted: Thu Mar 18, 2004 9:56 pm 
Newbie

Joined: Thu Mar 11, 2004 11:30 pm
Posts: 9
Hi,

I have two tables in Oracle9i Database. One is parent and the other is child. The table schema is as follows.

Award
-------
award_id number(14) (P.K)
scheme_code varchar2(15)
student_id number(14)
school_code varchar2(10)
award_start_date date
award_end_date date
provisional_ind char(1)
version_no number(6)

AwardStatus
--------------
award_id number(14) (P.K)
status_code varchar2(10)
status_date date
version_no number(6)

Relationship is One-to-Many and Many-to-one. I mean One Award table can have Many records in AwardStatus table and Many records in the AwardStatus table can have one Award.

How can i specify the mapping for these two tables? Currently i am specifying the mapping as follows.

Award
--------
<class name="Award" table="award">
<id generator="sequence" unsaved-value="0">
<param name="award_seq">next_val</param>
</id>
<version name="versionNo" column="version_no"/>
<property name="schemeCode" column="scheme_code"/>
<proeprty name="studentId" column="student_id"/>
<property name="schoolCode" column="school_code"/>
<property name="awardStartDate" column="award_start_date" type="date"/>
<property name="awardEndDate" column="award_end_date" type="date"/>
<property name="provisionalInd" column="provisional_ind"/>
<Set name="awardStatus" inverse="true">
<key column="award_id"/>
<one-to-many class="AwardStatus"/>
</Set>
</class>


AwardStatus
--------------
<class name="AwardStatus" table="awardstatus">
<id generator="assigned"/>
<version name="versionNo" column="version_no"/>
<property name="statusCode" column="status_code"/>
<property name="statusDate" column="status_date" type="date"/>
</class>


I am not able to understand how to specify Many-To-One relationship in the AwardStatus mapping since both are sharing the same primary key.

According to the documentation, i know that two classes should have different primary keys, but i dont have rights to change the database schema at the moment. Can any one help me in understanding how to map the relation for the above situation.

Thanks.

Regards.

Lokesh.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 10:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
If they share the same PK, then there is no way either side of the relationship can have a many multiplicity. This is a one-to-one relationship; check the docs on setting up a one-to-one association.

Unless the award_id column not really the *PK* of the AwardStatus table...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 11:06 pm 
Newbie

Joined: Thu Mar 11, 2004 11:30 pm
Posts: 9
Hi Steve,

Thanks for the reply.

award_id column in AwardStatus table is a Primary Key. This is the point that is putting me in trouble.

Any suggestion to make the schema changes?

thanks.

regards.

Lokesh.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 11:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
AwardStatus
--------------
award_status_id number(14) (P.K)
award_id number(14) (F.K)
status_code varchar2(10)
status_date date
version_no number(6)


?


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