-->
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.  [ 3 posts ] 
Author Message
 Post subject: inherited mapped class redux
PostPosted: Mon Jul 31, 2006 2:50 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 4:54 pm
Posts: 32
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

i have a class Foo that maps a single table in the database. all works well. Foo has a subordinate table, Bar. the DBA has provided a view that i map to FancyFoo. FancyFoo has all the Foo data plus some info from the 'latest' Bar associated with a specific Foo.

i've created a FancyFoo java object that extends my Foo java object, and i've copied Foo.hbm.xml to FancyFoo.hbm.xml, adding the extra attributes.

problem: i get duplicate results. for instance, my old query:
Code:
select count(foo) from Foo foo where foo.name like 'ZASU PITTS'

which used to return a count of one, now returns a count of two, even though there is only one ZASU PITTS.

from my trace, i can see what happens - sort of. in hibernate's HQLQueryPlan.performList method, i end up with two translators, one for Foo and one for Fancy Foo. the first one has the HQL:
Code:
select count(foo) from Foo foo where foo.name like 'ZASU PITTS'

and the other has:
Code:
select count(foo) from FancyFoo foo where foo.name like 'ZASU PITTS'

HQLQUeryPlan.performList runs each, and they both return a one, since they both successfully find ZASU PITTS, and then HQLQueryPlan combines the results - and the answer is two.

so, er, what is the proper way to do inheritance? or how do i get hibernate to not combine results?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 7:15 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 4:54 pm
Posts: 32
thinking about this on the drive home, it makes sense what is happening. it's the same thing happening that allows for the HQL:
Code:
from Object

to work. so hibernate walks the class hierarchy from the root class given (in my case Foo) and has each class that maps to hibernate run its query, then it collects all the results.

trouble is, i want it to not do that in this case. so is there a magic flag that will prevent it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 9:32 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 4:54 pm
Posts: 32
so the fix for this is to not have FancyFoo extend Foo, but just create a FooIF that both implement. there's beaucoup extra code in FancyFoo (all getters and setters), but it works, by gum


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