I just moved the address type from the address table to the person_address table but I dont want to change my classes - only the mapping file.
I have 3 tables:
person (person_id, last_name, ...)
person_address (address_id, address_type, person_id)
address(street, city, ...)
I have 2 classes:
public class Person {
private Set addresses = new HashSet();
private String lastName;
..
}
public class Address
private int addressType;
private String street;
private int city
...
}
Is it possible to modify my mapping file to map the address type? This would allow me to force a unique database constraint on Person /AddressType - which is a common pattern for many tables.
Here is my current mapping from person to addresses
Person.hbm.xml__________
<set name="addresses" table="person_address" cascade="save-update" lazy="false" fetch="join">
<key column="person_id" not-null="true" />
<many-to-many column="address_id"
unique="true" lazy="false" fetch="join"
class="com.project.model.common.AddressModel"/>
</set>
|