java - how can I persist this complex object to database using hibernate? -



java - how can I persist this complex object to database using hibernate? -

there database tables in mysql @ backend corresponding these classes foreign keys defined accordingly. allow me know if need set 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 utilize this: http://pastebin.com/yzymtbg3 build itinerary object. puzzling me, , don't know way handle using hibernate orm.

airsegmentbuilder segmentbuilder = new airsegmentbuilder(); segmentbuilder.adddepartureairport("jfk"); segmentbuilder.addarrivalairport("sfo");

i trying add together departure , arrival airport (objects) itinerary here. these objects in turn persist in database as:

airport:

id | name | terminal 1 | jfk | 1 2 | sfo | b1

so when need add together these airports itinerary, need fetch airport objects first using query based on name?; , attach these objects itinerary? 1 time have itinerary object built , save database using hibernate, able pick foreign keys correctly ?

assuming using xml configure hibernate stuff. may write itinerary.hbm.xml accomplish goal :

<many-to-one name="airport" class="pkg.airport" column="foregn_key1" not-null="true" fetch="join" /> <many-to-one name="airline" class="pkg.airline" column="foregn_key2" not-null="true" fetch="join" />

where airport, airline , itinerary tables in db. hope helps...

note - kind of example. may need update beans accordingly.

java hibernate orm foreign-keys

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -