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.