-->
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.  [ 5 posts ] 
Author Message
 Post subject: Figuring out the instance of the subclass
PostPosted: Wed Jan 31, 2007 1:51 pm 
Newbie

Joined: Mon Jul 10, 2006 1:47 am
Posts: 8
Hibernate version:
3.0

I have implemented table-per-class-hierarchy but when I do a select to retrieve an object I want to figure out what the class of that object is. Unfortunately instanceof does not always give me the correct class. Is there a way to achieve this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 2:14 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
Can we have more info? Perhaps a mapping class and just how you are 'running a select'? From your vague message, I can only make assumptions... like are you running a jdbc select statement or an hql statement? It seems like you arne't using hibernate to do your queries...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 7:05 am 
Newbie

Joined: Mon Jul 10, 2006 1:47 am
Posts: 8
Basically I have a hibernate class say X. X has one sub class Y. There is another hibernate class Z that holds a collection of X (or Y). When I retrieve the collection and do an instanceof X/Y and if the object in the collection should have been of class Y (sub class) it always shows the object as being of the class X. Thats the problem


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 8:14 am 
Newbie

Joined: Wed Mar 21, 2007 6:48 am
Posts: 2
When a class X has a subclass Y, and you have an object of Y (y), then "y instanceof X" is true. But when you have an object of X (x), then "x instanceof Y" is false. I hope this helps you?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 9:07 am 
Newbie

Joined: Mon Jul 10, 2006 1:47 am
Posts: 8
Yes I understand that. Let me explain the problem again
    I have a class X and an subclass Y (using the table per class hierarchy pattern)
    Class Z has a collection of objects of X and/or Y
    I load Z
    I iterate through the collection trying to detect the if the object is of class Y by doing
    Code:
    currObj instanceof Y


This comparison fails for objects that I know for sure are of of class Y


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