-->
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: Filters with Criteria or HQL
PostPosted: Fri Oct 05, 2007 2:51 pm 
Newbie

Joined: Thu Jan 11, 2007 1:44 pm
Posts: 3
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>


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.