-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with lazy load one-to-one
PostPosted: Tue Jul 13, 2004 10:43 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
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 Schema
Code:
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 Schema
Code:
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]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 8:32 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
Does anyone know what I am doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 11:06 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
Am I confusing one-to-many restrictions as in http://forum.hibernate.org/viewtopic.ph ... highlight= with one-to-one mapping?
--Angus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 10:51 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
Hrm, doesn't look like it. It seems that I might need to switch over to a many-to-one relationship. Before I do this, can I please get some confirmation that switching to many-to-one is the only way to lazy load a foreign key generated child?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.