I have read this page. To get the save and delete to work I have:
parent:
Code:
<class
name="org.guidestar.uk.fin.hibernate.FinHeader"
table="fin_header"
proxy="org.guidestar.uk.fin.hibernate.FinHeader"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="tarId"
column="tar_id"
type="java.lang.Integer"
unsaved-value="null"
>
<generator class="identity">
</generator>
</id>
<one-to-one
name="finBalSheetAsset"
class="org.guidestar.uk.fin.hibernate.FinBalSheetAsset"
cascade="all"
outer-join="false"
constrained="false"
/>
Child:
Code:
<class
name="org.guidestar.uk.fin.hibernate.FinBalSheetAsset"
table="fin_bal_sheet_assets"
proxy="org.guidestar.uk.fin.hibernate.FinBalSheetAsset"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="tarId"
column="tar_id"
type="java.lang.Integer"
>
<generator class="foreign">
<param name="property">finHeader</param>
</generator>
</id>
<one-to-one
name="finHeader"
class="org.guidestar.uk.fin.hibernate.FinHeader"
cascade="none"
outer-join="false"
constrained="true"
/>
Right now I can do the full select, insert, update, delete.
Are you saying I need to set the constrained on the parent to true as well? When I tried this I get an error:
Code:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: org.guidestar.uk.fin.hibernate.FinBalSheetAsset.finHeader
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1276)
at net.sf.hibernate.impl.SessionImpl.doDelete(SessionImpl.java:1244)
at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1172)
at net.sf.hibernate.engine.Cascades$1.cascade(Cascades.java:61)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.doDelete(SessionImpl.java:1260)
at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1172)
at org.guidestar.database.dm.HibernateDataManager.deleteObj(HibernateDataManager.java:304)
I would love to see a simple example for 1to1, lazy loaded, identy generation on parent, using the parent's key on the child.