I have read
http://www.hibernate.org/162.html . Here is what I have set up:
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, identity generation on parent, using the parent's key on the child. I have the key column on the child set to !null.
Do I need to reverse my constrained entries? I thought I read something about one-to-one lazy mappings needing to be bidirectional. That web page his hinting at unidirectional.
Parent SchemaCode:
CREATE TABLE [fin_header] (
[tar_id] [int] IDENTITY (1000, 1) NOT NULL ,
[last_modified] [smalldatetime] NOT NULL ,
CONSTRAINT [PK_fin_header] PRIMARY KEY CLUSTERED
(
[tar_id]
) WITH FILLFACTOR = 85) ON [FIN_FileGroup]
GO
Child SchemaCode:
CREATE TABLE [fin_bal_sheet_assets] (
[tar_id] [int] NOT NULL ,
[last_modified] [smalldatetime] NULL ,
CONSTRAINT [PK_fin_bal_sheet] PRIMARY KEY CLUSTERED
(
[tar_id]
) WITH FILLFACTOR = 85 ON [FIN_FileGroup] ,
CONSTRAINT [FK_fin_bal_sheet_assets_fin_header] FOREIGN KEY
(
[tar_id]
) REFERENCES [fin_header] (
[tar_id]
)
) ON [FIN_FileGroup]
GO
[/code]