Possible Duplicate:
Hibernate unidirectional one to many association - why is a join table better?
In the Hibernate online documentation, under section 7.2.3 One-to-many, it's mentioned, that:
unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended. You should instead use a join table for this kind of association.
I would like to know why? The only thing that comes to my mind is, it can create problems during cascade deletes. For example, Person refers to address on a one to many relationship on a foreign key, and the address would refuse to be deleted before the person.
Can anyone explain the rational behind the recommendation?
Here is the link to the reference document content: 7.2.3. One-to-many
I have copy pasted the actual content here:
A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended.
<class name="Person"> <id name="id" column="personId"> <generator class="native"/> </id> <set name="addresses"> <key column="personId" not-null="true"/> <one-to-many class="Address"/> </set> </class> <class name="Address"> <id name="id" column="addressId"> <generator class="native"/> </id> </class>
create table Person (personId bigint not null primary key) create table Address (addressId bigint not null primary key, personId bigint not null)
You should instead use a join table for this kind of association.