Hello.
I have following tables:
----------------
T_LOCATION
location_id
street_address
city
country
----------------
T_PERSON
name
location_id
----------------
T_COMPANY
name
location_id
----------------
The idea is to just extract all location specific information into separate table. Every row in the location table used only once - either single Person or single Company points to it.
Using <many-to-one> for Location in the Person class works, but when new location is set for the Person or Company, it is not automatically saved (I have to call session.save(location) before session.save(person)). Is it possible to make save() operation cascade in this scenario? Also I need to delete record from T_LOCATION when Person's location is replaced with totally new. Actually, I need behavior much like collection with cascade="all-delete-orphan" but I do not want to use collection because it is known, there can be only one location for Company, not a set of locations.
Or are there other ways to implement what I want? Eliminating T_LOCATION table, putting all the properties into T_PERSON/T_COMPANY and using <component> is definitely not the best idea because:
1. There actually more than two entities which use location.
2. Some entities has two references to the location table (home_location_id and office_location_id for instance)
2. There are much more fields in the T_LOCATION table than I put in this sample.
Thanks in advance.
|