Hi,
I'm getting started with JPA and created the following (simplified) tables;
airport
--------
id (pk)
city
code
...
trip
--------
id (pk)
originAirport_id (fk)
destinationAirport_id (fk)
...
I'm trying to map this in JPA/Hibernate.
In My trip object I created 2 airport objects:
private Airport airportFrom;
private Airport airportTo;
And I annotated the getters like this:
@ManyToOne
public Airport getAirportFrom() {
return airportFrom;
}
@ManyToOne
public Airport getAirportTo() {
return airportTo;
}
In my Airport class I created a HashSet of 'trip' objects
private Set <Trip> trips = new HashSet<Trip>();
And annotated the getter:
@OneToMany (mappedBy="airport")
public Set <Trip> getTrips() {
return trips;
}
This would be simple to implement in SQL but I don't know how to annotate and implement that relationship in JPA/Hibernate.
Any tips?