Hi!
I'm trying to make a one-to-one relation between a Person and his PersonData.
With the code below it works:
Code:
<class
name="candidato.hibernate.HPerson"
table="ca_candidato"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="read-write" />
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<one-to-one
name="anagrafica"
class="candidato.hibernate.HPersonData"
cascade="all"
outer-join="auto"
constrained="false"
/>
[...]
<class
name="candidato.hibernate.HPersonData"
table="ca_anagrafica"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="read-write" />
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="foreign">
<param name="property">candidato</param>
</generator>
</id>
<one-to-one
name="candidato"
class="candidato.hibernate.HPerson"
cascade="all"
outer-join="auto"
constrained="true"
/>
[...]
So i can store the two object simply with:
Code:
HPerson can=new HPerson();
can.addPersonData(new HPersonData());
session.save(can);
But if i want to have lazy initialization of HPersonData i must use a proxy and invert the constrained properties. If I invert the "constrained" it doesn't work no more and Hibernate say that the identifier is null (maybe caused by the foreign generator).
There is any solution to do lazy initialization of HPersonData in this scenario?
Thanks (and sotty for my poor english!)
Gio