My 0.02รง
The eg. by Regis Pires Magalhaes
Association: Person [1 <--> 0..1] Note
is not really a [1 <--> 0..1] but more of a 1 <----> 1
I find that for a Person if you DO NOT create a note, the save goes
through fine, but when you try to Load the Person.getNote() then:
1. a proxy is created
2. person.getNote() evaluates to not null even if there are no notes for
a person
3. person.getNote().getNoteDetails() or some such method bombs with an
Exception:org.hibernate.ObjectNotFoundException: No row with the given
identifier exists
In my experiments, rather, if this is modeled as a many-to-one from
Person to Note with a NOTE_ID being stored in the Person Table, then
that approach is much more conducive to a unidirectional Person [1 <-->
0..1] Note
Something like this in Person:
<many-to-one name="note" class="Note" column="NOTE_ID"
unique="true" cascade="all"/>
With this in Note:
<class name="Note" table="NOTE">
<id name="id" column="NOTE_ID" type="long">
<generator class="increment"></generator>
</id> |