We are having an issue where we are trying to use Hibernate Filters on top of either a Criteria or HQL. However, whenever we set a filter on the class or a Set within the class in the mapping file, the criteria or HQL is ignored and only the filter seems to be applied to the results. We need both the filter and the Criteria/HQL to also apply when Hibernate retrieves the data from the database.
There are no errors or anything, it is just that the filter condition is only being applied instead of the filter and the HQL Query or Criteria. So the filter works, but it overrides the HQL Query or criteria we set.
Are we supposed to be able to use filters in conjunction with either the Criteria or HQL? If so, what are we NOT doing that it isn't working?
We are using Hibernate 3.2.5 with MySQL 5.0.2.
The Java code is as follows:
final Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.enableFilter("includeDeleted").setParameter("deleted", this.isIncludeDeletedObjectsInResults());
this.getSession().createQuery("from Company as c where c.id = :id").setString("id", companyId);
final List list = query.list();
Company company = null;
if (list != null && list.size() == 1)
{
company = (Company) list.get(0);
}
The mapping file contains:
<class name="Company" table="COMPANY">
<id name="id" column="COMPANY_ID">
<generator class="assigned"/>
</id>
<version name="version" column="VERSION" unsaved-value="null"/>
<property name="dateAdded" type="timestamp" column="DATE_ADDED"/>
<property name="name" column="NAME"/>
<set name="sites" inverse="true" cascade="all,delete-orphan">
<key column="COMPANY_ID"/>
<one-to-many class="Site" />
<filter name="includeDeleted" condition="DELETED = 0 or DELETED = null or DELETED = :deleted"/>
</set>
<many-to-one name="managerUser" column="USERNAME" not-null="false"/>
<property name="deleted" not-null="true">
<column name="DELETED" default="false"/>
</property>
<filter name="includeDeleted" condition="DELETED = 0 or DELETED = null or DELETED = :deleted"/>
</class>
<filter-def name="includeDeleted">
<filter-param name="deleted" type="boolean"/>
</filter-def>
|