-->
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.  [ 1 post ] 
Author Message
 Post subject: Filtering Join to an Inheritance-Mapped Entity
PostPosted: Thu Jun 24, 2010 7:07 pm 
Newbie

Joined: Thu Jun 24, 2010 6:35 pm
Posts: 1
Hi

I'm having a little difficulty using filters.

I have an entity (e.g. DogBasket) which has a OneToMany association to another, inheritance-mapped entity (e.g. Dog). The "Many" entity extends from a superclass entity (e.g. Pet) and uses join-table inheritance mapping. The superclass has a property ("alive") which I'm trying to filter the collection based on:

Code:
                        +--------+
                        |  Pet   |-- alive
                        +--------+                           
                            ^
                            |
+-------------+ 1     * +--------+
|  DogBasket  | ------< |  Dog   |
+-------------+         +--------+


So I have the following filter definition at package level:

Code:
@FilterDef(name="alive", defaultCondition="alive = 1")


And in DogBasket I declare the filter on the collection of Dogs:

Code:
@OneToMany(mappedBy="basket")
@Filter(name="alive")
public Set<Dog> getDogs(){
   return dogs;
}


I then query for the DogBaskets and Dogs like this:

Code:
from DogBasket db
join fetch db.dogs


I'm expecting the resulting SQL query to have applied the filter condition to the superclass entity (Pet), because this is the entity to which the "alive" property belongs. Instead, Hibernate is trying to apply the condition to the subclass regardless:

Code:
select
   dogbasket0_.id as id2_0_,
   dogs1_.id as id0_1_,
   dogs1_1_.alive as alive0_1_,
   dogs1_.barkDecibels as barkDeci1_1_1_,
   dogs1_.basket_id as basket3_1_1_,
   dogs1_.basket_id as basket3_2_0__,
   dogs1_.id as id0__
from
   DogBasket dogbasket0_
   left outer join Dog dogs1_ on dogbasket0_.id=dogs1_.basket_id
      /* This condition is on the wrong table - it should be on Pet! */
      and dogs1_.alive = 1
   left outer join Pet dogs1_1_ on dogs1_.id=dogs1_1_.id


Is this a bug, or does Hibernate just not support filtering of inheritance-mapped entities at all?

I found this bug report which seems to be related (http://opensource.atlassian.com/project ... e/HHH-2113), though that seems to have been unresolved since 2007.

Any guidance at all would be much appreciated :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.