There are database tables in mysql at the backend corresponding to these classes with Foreign Keys defined accordingly. Let me know if I need to put those relations here.
class Itinerary {
Airport Departure;
Airport Arrival;
Airline flight;
}
class Airport{
int idAirport;
String terminal;
City city;
}
class City{
int idCity;
String name;
}
class Airline{
int idAirline;
String flightNumber;
}
I use something like this: http://pastebin.com/YzYMTBg3 to build an itinerary object. This is what is puzzling me, and I don’t know what is a good way to handle this using hibernate as my ORM.
AirSegmentBuilder segmentBuilder = new AirSegmentBuilder();
segmentBuilder.addDepartureAirport("JFK");
segmentBuilder.addArrivalAirport("SFO");
I am trying to add departure and arrival airport (objects) to my itinerary here. These objects in turn persist in database as:
Airport:
id | name | terminal
1 | JFK | 1
2 | SFO | B1
So when I need to add these airports to my itinerary, do I need to fetch the airport objects first using a query based on name?; and then attach these objects to itinerary? Once I have the itinerary object built and save it to the database using hibernate, would it be able to pick up the foreign keys correctly ?
Assuming you are using xml to configure your hibernate stuff.
You may write your Itinerary.hbm.xml like this to achieve your goal :
where Airport, Airline and Itinerary are the tables in your DB.
Hope this helps…
Note – This is just a kind of example. You may need to update your beans accordingly.