-->
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: NHibernateUtil.GetClass() initializes proxy
PostPosted: Fri May 16, 2008 3:02 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Hibernate version: 1.2.1.GA

I am having problems with calls to NHibernateUtil.GetClass() initializing proxies. Is this the expected behavior? I am using field based mapping, if that matters ...


Top
 Profile  
 
 Post subject: NHibernateUtil.GetClass() initializes proxy
PostPosted: Wed May 21, 2008 10:09 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

Yes, I think that's expected behaviour.

The only methods you can call on a proxy without it loading are:

1. The identifier accessor;
2. GetHashCode() (but only if Equals() isn't overridden);
3. The HibernateLazyInitializer accessor (only used internally).

I think that's it.

The code to look at is 'NHibernate.Proxy.Poco.BasicLazyInitializer.Invoke()' if you're curious.

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 11:21 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Is there any reason why NHibernateUtil.GetClass() doesn't just do this, which would avoid initializing the proxy:
Code:
return
    (proxy is NHibernate.Proxy.INHibernateProxy
    ? proxy.GetType().BaseType
    : proxy.GetType());


Top
 Profile  
 
 Post subject: NHibernateUtil.GetClass() initializes proxy
PostPosted: Wed May 21, 2008 11:29 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
I think it's to handle inheritance.

The proxy always inherits from the base-class in an inheritance chain ... but can instantiate a sub-class of that for the 'real' object.

There is a GuessClass() method on the NHibernateProxyHelper class that won't instantiate the proxy, but it's not guaranteed to return the correct result (hence the method name) on a mapping that has inheritance.


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.