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 :)