-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy initialization - property does not get initialized
PostPosted: Thu Jan 12, 2006 8:22 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
I decided to make it a new topic...

I have lazy initialization in a Data class:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Pix.Data.Data, Pix.Data" table="PICTURE" lazy="true">
    <id name="Id" column="ID" type="Int32"
          unsaved-value="0"access="field">
      <generator class="sequence">
        <param name="sequence">OBJECT_ID_GEN</param>
      </generator>
    </id>
    <property name="Bytes" column="IMAGE" type="BinaryBlob"
                    access="field" />
    <one-to-one name="Owner" class="Pix.Data.Picture, Pix.Data"
                       access="field" />
  </class>
</hibernate-mapping>


Great... But now when I read my stored Picture object, I do NOT have Data field being initialized. Can anyone explain it to me? Does the generic proxy implementation in NHibernate (it is Castle, isn't i?) work with fields? If it does then why just simple invokation:

Code:
void Read(ISession sess, int id)
{
  Picture pic = (Picture)sess.Load(typeof(Picture), id);
  ShowPicture(pic.Data.Bytes);
}


doesn't work? The Data property has been initialized (I see it is just the proxy), but the data in it is NOT. Owner is null, id is zero, Bytes is null.

When I don't use lazy loading then it works :|

For more details on the design please see my previous topic related to one-to-one relationship at http://forum.hibernate.org/viewtopic.php?t=953923

TIA

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Virtual
PostPosted: Thu Jan 12, 2006 11:36 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Have you tried setting the Data property in the Picture class as Virtual.


Top
 Profile  
 
 Post subject: Re: Virtual
PostPosted: Fri Jan 13, 2006 3:52 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
samujob wrote:
Have you tried setting the Data property in the Picture class as Virtual.


Well... I've made it virtual but it does not help.

Note that when no lazy init is being done then it works perfectly. But for me the lazy init was a benefit of the solutiion...

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Re: Virtual
PostPosted: Fri Jan 13, 2006 7:20 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
rolandz wrote:
samujob wrote:
Have you tried setting the Data property in the Picture class as Virtual.


Well... I've made it virtual but it does not help.

Note that when no lazy init is being done then it works perfectly. But for me the lazy init was a benefit of the solutiion...


Great!!! After I've read the topic at http://forum.hibernate.org/viewtopic.php?t=954014 I realized my mistake... Now it works. Thanx a lot :)

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Where in the documentation...
PostPosted: Fri Jan 13, 2006 8:28 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
Again,

Since I've missed a place in the documentation where exactly it is written that for proxy there must be a virtualization being applied, could somebody point me that place? Just for curiousity :)

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 8:40 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
http://www.hibernate.org/hib_docs/nhibernate/html/basic-mapping.html#mapping-declaration-class
http://www.hibernate.org/359.html#A5

I must admit that it's not exactly written in big bold blinking red, but it's there...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.