I have legacy db that cannot be modified. I have the following tables
doctor
--------
PK: ID
individual
---------
PK: ID
Head_Address
individual_address
-----------------
PK: ID
PK: Type
PK: Ind
So I have a 1-1 relationship from doctor.ID to individual.ID, no problem, but I have a many-many relationship between individual.Head_Address and individual_address.ID. The problem I'm running into is when an address belongs to more than one individual. I need to figure out a way to define a many-to-many relationship in hibernate without creating an intermediate table or extra columns? I am using a bag in this example, but could use a map. Any help would be appreciated. So my mapping looks like
<class name="Insured" table="doctor">
<id name="id" column="id" type="string">
<generator class="native"/>
</id>
<bag name="addresses" table="individual" lazy="false"> <key column="ID" property-ref="headAddress" /> <one-to-many class="InsuredAddress" />
</set>
<join table="individual" fetch="select">
<key column="ID"/>
<property name="headAddress" column="Head_Address"/>
....
</join>
</class>
On the address side, the mapping looks like
<class name="Address" table="individual_address">
<composite-id name="addressKey" class="AddressKey">
<key-property name="id" column="ID" />
<key-property name="type" type="string" column="Type
<key-property name="ind" type="integer" column="Ind"/>
</composite-id>
....
</class
|