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.  [ 3 posts ] 
Author Message
 Post subject: joined subclass issues
PostPosted: Tue Nov 24, 2009 7:48 pm 
Newbie

Joined: Thu Nov 05, 2009 2:39 pm
Posts: 7
Hi,

I'm having a problem finding the type of my joined subclasses.

I have two subclasses, and one parent class. For example, I have one class Pets, and two joined subclasses: Dogs, and Cats.

my problem is that the proxy is creating a culmination of all these classes, so if I write:

Code:
if(pet is Dogs)
returns true AND

Code:
if(pet is Cats)
also returns true

The only way to really tell is to look at the properties that Dogs and Cats dont have in common, if the object is a Cat, the Dog properties will throw errors if I try to access them. But this is pretty sloppy. How can I ask Nhibernate what the underlying type of my joined subclass is?


Top
 Profile  
 
 Post subject: Re: joined subclass issues
PostPosted: Wed Nov 25, 2009 7:08 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You probably need to create interfaces for the proxies.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: joined subclass issues
PostPosted: Wed Nov 25, 2009 11:58 am 
Newbie

Joined: Thu Nov 05, 2009 2:39 pm
Posts: 7
Right, if I create the same concept with these classes as, instead, interfaces, and say

Code:
IPet pet = new Dog();
if (pet is IDog)


returns true for both IDog and ICat, because NHibernate creates a weird proxy superclass that is the culmination of Pets, Dogs, and Cats properties, all combined.

I suppose this is my real question and issue. If I had another joined subclass, say lizards, the object would contain all the properties of DOG, CAT, PET, and LIZARD!

The only real way to tell what is the real type of the object is to look at the properties exclusive to a cat, or dog, and see if accessing them doesn't throw an exception. For example, if I say
Code:
try { dog.Bark; } catch { //object is not a dog }


but this is hacky and not cool.


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