Class filter not included in JOIN queries in Hibernate
Issue
- A
to-manyassociation exists where the many side of the association also has a filter applied
@Entity
public class Person {
@OneToMany
private Address address;
...
}
@Entity
@Filter(condition="filterId = :filterId", name = "filterId")
@FilterDef(name="filterId", parameters=@ParamDef( name="filterId", type="int" ) )
public class Address {
...
}
- The filter is enabled in code at runtime
session.enableFilter("filterId").setParameter("filterId", Integer.valueOf(1234));
- The filter is automatically applied when queries are directly executed against the filtered class but not when the class is part of a join query
Query query = entityManager.createQuery("SELECT p, a FROM Person p JOIN p.address a");
select
person0_.ID as ID1_2_0_,
address1_.ID as ID1_0_1_,
...
from
PERSON person0_
inner join
ADDRESS adress1_
on person0_.FK_ADDRESS=adress1_.ID
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
