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.  [ 6 posts ] 
Author Message
 Post subject: inheritance: 'discriminatorType' injected to a datamember
PostPosted: Tue Sep 02, 2008 5:57 pm 
Newbie

Joined: Mon Feb 18, 2008 4:46 am
Posts: 6
hi,

is there a way for the 'discriminatorType' to be injected to a datamember of a class ?

or in other words, how can i check a type of an entity ?
i cannot use the instanceof because the class i get, can be a proxy !

thanks,
Eran.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 9:42 pm 
Newbie

Joined: Thu Jan 29, 2009 9:36 pm
Posts: 2
Hi!

Can somebody give us a hint with this topic?

I've got two classes, Person, and Student. Student is a subclass of Person.

Now, I've got a List of Person, but some of it's elements are students. How am I supposed to cast these objects so that I can access fields and methods declared in Student?


Thanks in advance.


Top
 Profile  
 
 Post subject: solution
PostPosted: Sat Jan 31, 2009 5:42 pm 
Newbie

Joined: Mon Feb 18, 2008 4:46 am
Posts: 6
you can use Hibernate.getClass(yourObject).

that way you will get the actual class and then decide to which class to cast it.

pay attention, that the object's data will be "retrieved" - meaning, if your object is "lazy" it will no longer be that and its data will be retrieved - and you might performance penalty for that (depends what you want to achieve).

Eran


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 4:47 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Also you could try to implement your own "proxy-interfaces". It is described here.

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


Top
 Profile  
 
 Post subject: hey
PostPosted: Mon Feb 02, 2009 7:34 am 
Newbie

Joined: Mon Feb 02, 2009 7:11 am
Posts: 1
Wow! your documentation is very nice.. thanks..

_________________
data entry services india


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 4:32 pm 
Newbie

Joined: Thu Jan 29, 2009 9:36 pm
Posts: 2
Thank you both for your help!

I think proxies are too complex for me, so I will try getClass. I'm now looking for a way to use it without "polluting" my classes with Hibernate calls. Maybe there's a general way to do it..


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