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.  [ 2 posts ] 
Author Message
 Post subject: Polymporphism: Retrieval of Real Type of Object
PostPosted: Sat Aug 28, 2004 2:24 am 
Newbie

Joined: Sat Aug 28, 2004 1:47 am
Posts: 4
Hi,

This posting is to discuss the issue of how to make out real type of an (associated) entity that is retrieved by using polymorphism.

Let us take the case of entity type B being associated to entity type A. B', B", ... are subtypes of B. A typical code to retrieve instances of B (or its subtypes) would be,


A a = (A) session.get (A.class, aid);
B b = a.getB();
B' bb = (B') session.load (B'.class, b.getId());
...

As we can see here, an object of type B' gets created because the code specifies B'.class.

As far as context of A is concerned, it should suffice to use instance of B' as instance of B. But outside of this context, the application code may want to know the real type of the instance.

How does application know real type? Does Hibernate support retrieval of real type? Or is it a responsibility of the application to retrieve the real type of an instance by (storing and) retrieving "real-type" field from the DB?

Please let us know and thanks a lot for your help.

Regards,
Jay


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 28, 2004 2:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The whole point of Hibernate is that it takes care of polymorphism for you. In some cases, the proxy type might not be as narrow as the underlying instance type, in which case you can use Hibernate.getClass() to discover the underlying instance type that is being "hidden" by the proxy.


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