-->
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: Many-to-one association confusion
PostPosted: Wed Aug 27, 2008 11:23 pm 
Newbie

Joined: Mon Aug 11, 2008 5:35 am
Posts: 1
Hi,

I have 2 classes (1) Designation (2) Responsibility. A designation can have multiple responsibilities, so I created a Set for the same in the Designation Class to get all the responsibilities for a Designation. Below are the details:

Class Designation {
private Integer id;
private String name;
private Set<Responsibility> responsibilities;

Getters & Setters.....
}

Table Structure for Designation: id, name

Class Responsibility {
private Integer id;
private String name;
private Integer designation_id;

Getters & Setters.....
}

Table structure for Responsibility: id, name, designation_id

Hibernate Mapping:
<set name="responsibilities">
<key column="designation_id" />
<one-to-many class="Responsibility" />
</set>

Now, I am not sure whether the above mapping is correct or not. If its correct, what does it mean in simple words, what does <key> column mean with respect to the above mapping.

Thanks
Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 6:05 pm 
Newbie

Joined: Thu Aug 28, 2008 5:55 pm
Posts: 1
With my understanding of Hibernate I will try to explain.

-This mapping file is for Designation.

<set name="responsibilities">
-->You will have getter and setter methods for the 'responsibilities' in the Designation class
<key column="designation_id" />
-->primary key field in Designation class
<one-to-many class="Responsibility" />
-->You are saying that relation to the Responsibility class is one to many and collection contains elements of type 'Responsibility'


Top
 Profile  
 
 Post subject: Re: Many-to-one association confusion
PostPosted: Sat Aug 30, 2008 9:23 am 
Newbie

Joined: Sat Aug 30, 2008 6:22 am
Posts: 2
gauravrajbehl wrote:
Hi,

I have 2 classes (1) Designation (2) Responsibility. A designation can have multiple responsibilities, so I created a Set for the same in the Designation Class to get all the responsibilities for a Designation. Below are the details:

Class Designation {
private Integer id;
private String name;
private Set<Responsibility> responsibilities;

Getters & Setters.....
}

Table Structure for Designation: id, name

Class Responsibility {
private Integer id;
private String name;
private Integer designation_id;

Getters & Setters.....
}

Table structure for Responsibility: id, name, designation_id

Hibernate Mapping:
<set name="responsibilities">
u can have a set of responsibilities related to this Designation.
<key column="designation_id" />

This refers to the foreign key property of the responsibilities field.There will be a designation_id property in the responsibilities class/table mapping to the primary key of designation.

<one-to-many class="Responsibility" />

From a desigantion to many responsibilities!

</set>

Now, I am not sure whether the above mapping is correct or not. If its correct, what does it mean in simple words, what does <key> column mean with respect to the above mapping.

Thanks
Regards


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.