-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with class and superclass
PostPosted: Wed Mar 21, 2007 6:40 am 
Newbie

Joined: Wed Feb 07, 2007 12:48 pm
Posts: 3
Hi to everybody!
I read some old topic but i don't found nothing useful for this issue.
I want to know if it is really possible to load from db a single object without pull up the entire child class instance.
In other word i need to load the class A that have been specialized in class B, class C.....class Z, i don't want to need to load one istance for each single class, i just want an istance of class A!

I know about the existence of polymorphis tag and annotation but i understand, throw other topic, that this doesn't work in the actual versione of hibernate.

thank to everybody, and i apologise for my terrible english.

N@ruto


Top
 Profile  
 
 Post subject: Re: Problem with class and superclass
PostPosted: Wed Mar 21, 2007 10:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
N@ruto wrote:
I know about the existence of polymorphis tag and annotation but i understand, throw other topic, that this doesn't work in the actual versione of hibernate.


I am not aware of a bug, and for sure no one gave me a reproducible test case for it.
For you case, it is not supported in Hibernate because it is not supported in Java. If you have an instance of class B (subclass of A), there is no way (and no need) to convert it into an instance of A only, it is by essense an instance of class B.
What polymorphism=explicit does is

B subclass of A and B polymorphism explicit and B the root entity (not a subclass),
Then from A will not return Bs
More formally
Quote:
Implicit polymorphism means that instances of the class will be returned by a query that names any superclass or implemented interface or the class and that instances of any subclass of the class will be returned by a query that names the class itself. Explicit polymorphism means that class instances will be returned only by queries that explicitly name that class and that queries that name the class will return only instances of subclasses mapped inside this <class> declaration as a <subclass> or <joined-subclass>. For most purposes the default, polymorphism="implicit", is appropriate. Explicit polymorphism is useful when two different classes are mapped to the same table (this allows a "lightweight" class that contains a subset of the table columns).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 11:54 am 
Newbie

Joined: Wed Feb 07, 2007 12:48 pm
Posts: 3
I don't want to convert B into an instance of A.
Maybe i wrong to explain.

I have this :

Class A
Class B extend A
Class C extend A

if i try to load a object of class A in the query that make the selection i see that there is a join that involve the table of class A, class B and class C, but this is not usefull if i try to load just A.

I have this problem also i try to load just an object of Class B, i see the same join with the table A (right) and join with table C!!

I try to make a simple test about this (i don't be able to send my application :D) and show you this.

thank you very much for the answer.
N@ruto


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is the expected behavior. We don't upcast.

_________________
Emmanuel


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