-->
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: One to many relationship
PostPosted: Thu Mar 10, 2005 9:21 am 
Newbie

Joined: Fri Mar 26, 2004 7:23 am
Posts: 19
Hi all,

I have a problem regarding the mapping of 2 classes in a one to many relation.


I have 2 classes namely Reiser.java and Station.java.
Reiser.java contains the list of Station. and the association is unidirectional and Station.java does not contain an object of type Reiser.

some code in Reise.java//
/**
* List: Station
*/
private List station;

This is a clear cut one-to-many association .
And i would like to know whether i need to have a foreign key field in the file Station.java in order to have a one to many association from Reise to Station.

Thanx in advance
Agatha


Top
 Profile  
 
 Post subject: Re: One to many relationship
PostPosted: Thu Mar 10, 2005 10:07 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 9:24 am
Posts: 28
Agatha wrote:
Hi all,

I have a problem regarding the mapping of 2 classes in a one to many relation.


I have 2 classes namely Reiser.java and Station.java.
Reiser.java contains the list of Station. and the association is unidirectional and Station.java does not contain an object of type Reiser.

some code in Reise.java//
/**
* List: Station
*/
private List station;

This is a clear cut one-to-many association .
And i would like to know whether i need to have a foreign key field in the file Station.java in order to have a one to many association from Reise to Station.

Thanx in advance
Agatha


You just need to have a reise foreign key column in your STATION table.

and your mapping must look like this:

<class
name="Reise"
table="REISE">
.......................

<set name="station">
<key column="REISE_ID"/>
<one-to-many class "Station"/>
</set>

</class>

If you want to make your association a bidirectional many to one, you must have a raise property in the Station class like below:

public class Station {

private Raise raise;

...

}

the getRaise() object returned will be mapped by a foreign key in you Station table.


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.