-->
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.  [ 10 posts ] 
Author Message
 Post subject: Component not loaded
PostPosted: Mon Nov 21, 2005 4:47 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I have mapped a component for one of my entities and if I get a proxy of the entity by using
Code:
session.Load(persistentType, id);
, and then I access the component property of the entity like this:
Code:
memberAccount.Audit
, the component is null.

Here is my component mapping:
Code:
<component name="Audit" class="EntityAuditRecord" access="field.camelcase-underscore" >
         <property name="DateCreated" column="DateCreated" not-null="true"  access="nosetter.camelcase-underscore" />
         <property name="DateModified" column="DateModified" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" access="nosetter.camelcase-underscore"/>
         <many-to-one name="CreatedBy"  column="CreatedByMemberId" class="Member" not-null="true" outer-join="false" access="nosetter.camelcase-underscore"/>
         <many-to-one name="ModifiedBy"  column="ModifiedByMemberId" class="Member"  outer-join="false" access="nosetter.camelcase-underscore"/>
      </component>


If I load the object immediatly with
Code:
session.Get(persistentType, id);
everything works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:05 pm 
Regular
Regular

Joined: Fri May 13, 2005 4:08 pm
Posts: 64
Is your MemberAccount.Audit attribute marked virtual? Proxied classes must have all their persisted properties marked virtual (unless you use interfaces) to avoid returning null.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 7:30 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
aarnott, you are the man. Every property on that object was marked virtual except for that one. Good catch.

Thanks alot.


Top
 Profile  
 
 Post subject: Where do you mark a "property" virtual?
PostPosted: Mon Mar 20, 2006 7:52 pm 
Newbie

Joined: Mon Mar 20, 2006 7:40 pm
Posts: 8
I'm a long time OO developer, and have been using Java for years. I've been writing Hibernate code for a few months, and I seem to have been bitten by this same bug in a few places, but I don't know how to interpret the terminology of the solution that aarnott provided. I have some fields that I can see in the debugger (in Idea) have had their proxies loaded, but when I try to access the values that are clearly loaded in the proxies, I get null instead.

"virtual" isn't an attribute that I can declare for a Java field or method. I don't see a place to declare "virtual" in the hbm.xml. What do you mean by property or attribute? Where do you add this declaration?

This forum thread

http://forum.hibernate.org/viewtopic.php?t=952520

uses the same terminology, and it was apparently just as enlightening for rbrady as for you, but I'm not getting it.

The only thing I've been able to make work is declaring the field to be outer-join=true in the parent class. I shouldn't have to do that to get loaded proxies to provide access to the state they've already loaded.

Thanks.

_________________
Chris Hibbert
Prediction Markets
http://zocalo.sourceforge.net/
http://blog.commerce.net


Top
 Profile  
 
 Post subject: Java doesn't have a virtual keyword
PostPosted: Mon Mar 20, 2006 9:50 pm 
Regular
Regular

Joined: Fri May 13, 2005 4:08 pm
Posts: 64
Chris,

I think I know where the source of your confusion lies. In Java, I think every method is automatically virtual. Thus there is no "virtual" keyword in Java. In C#, methods are only virtual when that keyword is added, like this:

public virtual string getName() {...}

So if you're getting nulls where you think you should be getting objects and you think proxy objects are at fault, I think there must be another problem (which I am not aware of). The virtual thing can't possibly bite you in Java.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 10:15 pm 
Newbie

Joined: Mon Mar 20, 2006 7:40 pm
Posts: 8
C#! Oh, I get it. Too bad. Well, I do have a workaround (setting outerjoin=true causes the field to be filled absolutely.) This is unsatisfying, since outerjoin is supposed to be a caching hint, rather than a correctness step. I don't understand why accessing an instance variable doesn't work when I can see that the proxy has the value in it's grasp.

Thanks for your help. At least I understand why this answer wasn't relevant to me.

_________________
Chris Hibbert
Prediction Markets
http://zocalo.sourceforge.net/
http://blog.commerce.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 2:29 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
ChrisHibbert wrote:
C#! Oh, I get it. Too bad. Well, I do have a workaround (setting outerjoin=true causes the field to be filled absolutely.) This is unsatisfying, since outerjoin is supposed to be a caching hint, rather than a correctness step. I don't understand why accessing an instance variable doesn't work when I can see that the proxy has the value in it's grasp.


In NHibernate, the proxy is loaded as soon as first virtual method inside it is used. If a field mis accessed aoutside the class, there's nothing that can trigger loading... So, You might try to add some getter method for field and see if accessing field trought that triggers proxy loading.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 2:27 pm 
Newbie

Joined: Mon Mar 20, 2006 7:40 pm
Posts: 8
That's what I thought must have been going on at first, too. But this occurs in a situation in which a message has been sent to the class, and we're now executing inside it. I can see that the CGLib proxy has the state of the object, and in some cases has responded correctly to previous messages. In the error case, the CGLib state is present, but inside a method of the class, when I access an instance variable (with foo, this.foo, or this.foo()), the proxy seems to return the contents of the instance variable (null) rather than the state that is held in the CGLib's copy of the object.

Is there a difference between NHibernate and Hibernate that I need to be aware of? I'm using Hibernate 3.0, which includes cglib 2.1. (Is NHibernate for C#?)

To repeat, the proxy has clearly been loaded, but for some reason, its fields aren't being accessed.

Thanks for your help.

_________________
Chris Hibbert
Prediction Markets
http://zocalo.sourceforge.net/
http://blog.commerce.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 3:16 pm 
Regular
Regular

Joined: Fri May 13, 2005 4:08 pm
Posts: 64
ChrisHibbert wrote:
Is NHibernate for C#?


NHibernate is for all .NET languages, of which C# seems to be the most popular.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 6:26 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
ChrisHibbert wrote:
To repeat, the proxy has clearly been loaded, but for some reason, its fields aren't being accessed.


You should better ask this question in Hiberante forum... We here propably do not have knowledge to help with Java Hibernate issues.

Gert


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