-->
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: How to distinguish the sub calss object
PostPosted: Wed Jan 12, 2005 10:25 pm 
Newbie

Joined: Wed Dec 08, 2004 10:35 pm
Posts: 7
Hibernate version:2.17c

Hello,

I have a class User, with two sub-classes Doctor and Patient, I use Table Per Class Hierarchy mapping the class inheritance to the table User.
i.e, I have used a discriminator (column UserType).

My question is, when I retrieve a User instance from User table, how can I know the User is a a Doctor or Patient, that is, how can I get the discriminator value? (Hibernate will automatically set and retrieve the discrimnator values < from hibernate in Action>).

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:08 am 
Newbie

Joined: Wed Jan 12, 2005 8:58 am
Posts: 3
You use the instanceof operator.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:23 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Just a warning: Be careful of using the instanceof operator when you have provided a proxy for your objects.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 7:31 am 
Newbie

Joined: Thu Jan 13, 2005 6:34 am
Posts: 2
Location: Markt Indersdorf, Germany
The instanceof seems to work well with version 2.17 but fails with 3.0Beta1. Is this intended? And when, how to find out the subtype?
the debugger says:
the return object is of type <base-class>$$EnhancerByCGLIB$$...
This has two additional fields:
CGLIB$$BOUND=true
CGLI$$CALLBACK_0=CGLIBLazyInitializer
The CGLIBLazyInitializer in turn has a field target that is of type <sub-class>.
How can i get access to this information?

khs
[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 3:19 pm 
Newbie

Joined: Wed Dec 08, 2004 10:35 pm
Posts: 7
Thanks a lot. I will try.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 3:42 pm 
Newbie

Joined: Wed Dec 08, 2004 10:35 pm
Posts: 7
Hello,

Actually I am still comfused with that.

Now class inheritance is like:

class User{};
class Doctor extends User{};
class Patient extends User{};

With "table per class hiberarchy" to map table User, with discriminator UserType

Now I retrieve User u = findByID() from table User, then can we use "instanceof" to get whether u is a Doctor or a Patient?

I doublt that, because (parent_instnace instanceof child_class), for exampe, (u instanceof Doctor) should create compile error, right?

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 5:52 am 
Newbie

Joined: Thu Dec 23, 2004 7:03 am
Posts: 5
Location: Brasov, Romania
work fine for me

thanks croco


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 2:07 pm 
Newbie

Joined: Thu Dec 30, 2004 6:58 pm
Posts: 6
What about when a Doctor is also a Patient? How can you get away with having a row in each of your subclasses that share a single row in the parent class?


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.