Summary:The Hibernate filter's parameters are not populated when an entity's Collection is populated using a fetch mode of subselect.
Details:I have a class (MyClass) with 2 collection properties: catalysts and attributeValues. Both are annotated to use a lazy fetch, and to use a subselect to do the fetching (see the sample code with annotations below).
The attributeValues collection is loaded with the same query that loads MyClass, using a fetch-join.
Code:
select e
from MyClass e
left join fetch e.attributeValues
When I have the query configured to run WITHOUT the filter, it runs fine. i.e. the "filterAttributeIds" parameter to the query is correctly populated. (See code below for the filter which looks like: ATTRIBUTE_ID in ( :filterAttributeIds ) ).
However when I have the query configure to run WITH the filter, the initial select runs correctly (the "filterAttributeIds" are correctly populated).
However when I force the load of the catalysts collection by doing:
Code:
MyClass myclass = ...;
...
myclass.getCatalysts().size();
The subselect correctly includes the filter, but the "filterAttributeIds" parameter is not populated, and the query throws an appropriate exception.
This is all taking places in the context of a single Hibernate session.
My understanding is that the subselect is supposed to be the same query as the original select. In my case, the query is correct, however the parameters are no begin populated.
Is there something I must do to get the "filterAttributeIds" into the query for the catalysts, or is there a bug in Hibernate?
Code:
class MyClass {
/*
*/
@OneToMany(
fetch = FetchType.LAZY,
mappedBy = "policyDomainObject"
)
@MapKey(name = "catalyst")
@Fetch(FetchMode.SUBSELECT)
public Map<Catalyst, PolicyCatalystLink> getCatalysts()
{
if (null == m_Catalysts)
{
m_Catalysts = new HashMap<Catalyst, PolicyCatalystLink>();
}
return m_Catalysts;
}
/*
*/
@OneToMany(
cascade = CascadeType.ALL,
mappedBy = "domainObject"
)
@Fetch(FetchMode.SUBSELECT)
@Filters(
value = {
@Filter(
name = "filterAttributeValuesByAttributeIds",
condition="ATTRIBUTE_ID in ( :filterAttributeIds )"
)
}
)
public Collection<AttributeValue> getAttributeValues()
{
if (null == m_AttributeValues)
{
m_AttributeValues = new ArrayList<AttributeValue>();
}
return m_AttributeValues;
}
}