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: Many-To-One, Proxies and Inheritance
PostPosted: Wed Oct 24, 2007 5:50 pm 
Newbie

Joined: Sun Aug 20, 2006 8:09 pm
Posts: 8
Hi everybody !

I encountered a problem using a Many-To-One Relation and the inheritance mapping feature. I using the table-per-subclass strategy.

I'm not sure if my mapping/configuration is wrong or NHibernate does not support the fuctionality I try to use.

I will try to describe my scenario with code:

class SomeClass
{
// this property is mapped via many-to-one
public virtual MappedClass MyClassObject
{
get... set...
}
}

class MappedClass
{ // some stuff here }

class MappedSubClass : MappedClass
{ // some more stuff here }


If I set the propertry

someClass.MyClassObject = new MappedSubClass();

everything is correctly stored in db. You may have recognized: I stored the inherited class and not the base class the mapping was actually written for.

If I try to access the MyClassObject after the next load, a ProxyObject is present. That's ok. I can cast the Proxy object to MappedClass.

BUT: I can't cast the Proxy object MappedSubClass. The Proxy object generated by NHibernate has the base MappedClass. If i load the object via the Id manually, it actually is of type MappedSubClass.

if I disable Lazy loading, the Property MyClassObject contains an object of type MappedSubClass, which is correct. So the problem seems to be the proxy. No matter which actual sub-class the reference points to, NHibernate always creates a proxy for the base class.

Is this a known behaviour? Is there a way use proxy is this scenario anyhow?

Thanks for help,
Thomas

NHibernate Version: 1.2.0.GA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 3:09 am 
Newbie

Joined: Fri Feb 08, 2008 3:08 am
Posts: 2
Location: Cape Town, South Africa
I have the exact same problem. Did you solve this yet?


Top
 Profile  
 
 Post subject: Visitor pattern
PostPosted: Fri Feb 08, 2008 6:59 am 
Newbie

Joined: Fri Feb 08, 2008 6:53 am
Posts: 4
Your solution may be in this document:

http://www.hibernate.org/280.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 7:05 am 
Newbie

Joined: Fri Feb 08, 2008 3:08 am
Posts: 2
Location: Cape Town, South Africa
Perfect. Thanks!


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.