-->
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: Class not correctly determined for InheritanceType.JOINED
PostPosted: Fri Feb 25, 2005 10:44 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
I have the following constellation

Unit
Section extends Unit
Chapter extends Unit

Unit has two methods getParent() and getChildren() that are mapped via a ManyToOne/OnToMany

Now, if a Section is parent to a Chapter, what should the getParent() call return? I expected, that the inheritance is respected with this mapping, but the call returns a Unit-Object.

This, of course is consistent with the targetEntity determined by the getParent():Unit-Call - but if breaks the Type-Scheme. Is there a way around this? Casting, of course, does not work, as the parent is only fetched with the data for Unit and misses all Section-Fields....

thx for the help!
stf


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:18 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If parent is actually fetched, you should be able to down cast.
But it seems your domain model is broken if you need to cast.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 2:39 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Is the model really broken? In unit, the model says, that

getParent():Unit returns Unit

and getChildren():List<Unit> also returns Units, and not the subclasses.

Therefore, only Unit appears as target-entity in the joins. getParent() and getChildren is not overwritten in the subclasses. Is this domainmodel already wrong?

How does hibernate determine the right classes for the fetched entities in this case?

As I've seen, hibernate joins to all possible joined-tables. Does it then look which columns are filled to determine which of the joined-tables had a hit?


thx for the help!
stf


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate returns you the correct subentity by outer-joining all the tables and finding which columns are not null. Of course it can't when the association is lazy (the proxy is of the super entity type).

_________________
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.