-->
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.  [ 8 posts ] 
Author Message
 Post subject: GetType() problem in Proxys when use many-to-one rel
PostPosted: Tue May 15, 2007 4:09 pm 
Newbie

Joined: Mon Oct 23, 2006 10:08 am
Posts: 7
Location: Buenos Aires - Argentina
i have a class mapped in many-to-one relationship with lazy="true", when i call GetType() form this class i get a type of a Proxy instead of the type of my class.
If i set lazy="false" all works fine.

Sorry my english

Hibernate version: NHibernate 1.2.0.GA
.NET framework: 1.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:26 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is not a problem, this is expected.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 5:05 pm 
Newbie

Joined: Mon Oct 23, 2006 10:08 am
Posts: 7
Location: Buenos Aires - Argentina
Maybe i'm confused but i try to explain it better with a example:

I have two classes with this map:
Code:
<class name="Parent">
  <id name="id">  ...  </id>
  <many-to-one lazy="true" name="child" class="Child" ... />
</class>

<class name="Child">
  <id name="id">  ...  </id>
</class>


if parent is a instance of a persisted Parent:
parent.child.GetType(); its returns a type of a Proxy of NHibernate

but if turn lazy="false":
Code:
<class name="Parent">
  <id name="id">  ...  </id>
  <many-to-one lazy="false" name="child" class="Child" ... />
</class>


when a i call parent.child.GetType(); it return the type of Child, and i think that's the expected i both cases, cause in the 2 examples parent.child is a instance of Child independently of the way that is "hydrated".

I hope it's be more clear, and thaks for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 1:03 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, due to the fact that NHibernate proxies are subclasses of the proxied types, of course if you call proxy.GetType(), you are going to get the proxy type. If you enable lazy loading, you get a proxy, if you don't enable lazy loading, you don't get a proxy.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:11 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You can use NHibernateUtil.GetClass to find the underlying real type of a proxy.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 8:57 am 
Newbie

Joined: Mon Oct 23, 2006 10:08 am
Posts: 7
Location: Buenos Aires - Argentina
Ok, thanks for answer me. I just wonder why the Proxy not overrides GetType() to return the type of the real class, but i was wrong.
Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
A proxy can't override GetType() because it's not overridable (for a good reason, otherwise how would you find out the real type of an object?).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:43 am 
Newbie

Joined: Mon Oct 23, 2006 10:08 am
Posts: 7
Location: Buenos Aires - Argentina
Exactly, thats was my mistake


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