Hi,
I have 2 tables (on MySQL, * = primary key).
1. Flight (flight_id*, flight_number, ....)
2. Stopovers (flight_number*, airport*, list_index)
I've got one class (Flight.java) and want to maintain a List of airports within based on the flight number(which is not the key).
Code:
public class Flight {
private String flightId;
private String flightNumber;
private List stopovers;
public String getFlightId() {
return flightId;
}
public List getStopovers() {
return stopovers;
}
public String getFlightNumber() {
return flightNumber;
}
..............
}
Mapping documents:Code:
<hibernate-mapping>
....
<id
name="flightId"
column="flight_id"
type="java.lang.String"
unsaved-value="null"
>
<generator class="uuid.hex">
</generator>
</id>
<property
name="flightNumber"
type="java.lang.String"
column="flight_number"
/>
<list
name="stopovers"
table="stopovers"
lazy="true"
cascade="none"
>
<key
>
<column
name="flight_number"
/>
</key>
<index
column="list_index"
/>
<element
column="airport"
type="string"
not-null="false"
unique="false"
/>
</list>
....
problem
The code works but it builds the relationship between the primary keys Flight(flight_id*) and Stopovers (*flight_number), so when it create a flight it adds the value of flight_id (which is hex) to the Stopover(flight_number).
What I want to achieve is to have the relationship between Flight(flight_number) and Stopovers (*flight_number).
How can I achieve this ?
Appreciate any help.