嗨我使用Hibernate 3.2与1.6 JDK和Mysql 5.0我试图使用标准api来放在一起动态过滤器。但是,当我添加一个限制的一组枚举是我的Criteria对象的属性时,我得到一个org.hibernate.exception.GenericJDBCException。休眠标准过滤一组枚举值
我的代码是这样的:
public class FollowUp {
...
public Set<AdminCategory> getAdminCategories() {...}
public void setAdminCategories(Set<AdminCategory> _arg) { ... }
}
我的Hibernate映射文件都有一组枚举值作为休眠文件中规定: http://docs.jboss.org/hibernate/stable/core/reference/en/html/collections.html#collections-ofvalues。该文件(FollowUp.hbm.xml )就是这样
<hibernate-mapping>
<typedef class="dao.util.HibernateAdminCategoryType" name="main-category" />
<class name="FollowUp" table="follow_up">
<!-- other properties here -->
<set name="mainCategories" table="follow_up_main_categories" fetch="join" lazy="false">
<key column="fup_id"/>
<element column="identifier" type="main-category"/>
</set>
<!-- other stuff -->
</class>
</hibernate-mapping>
的标准过滤器的代码是这样的:
public void runFilter(FollowUpFilter _filter) {
Criteria criteria = this.getSession().createCriteria(FollowUp.class);
if (_filter.hasMainCategories()) {
criteria.add(Restrictions.in("mainCategories", _filter.getMainCategories()));
}
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setProjection(Projections.rowCount());
Integer count = (Integer) criteria.uniqueResult();
_filter.setTotalSize(count);
}
当我运行我的测试(与SQL输出)我得到以下错误:
Statement parameter 1 not set.
org.hibernate.exception.GenericJDBCException: could not execute query
的sql输出如下:
select
count(*) as y0_
from
follow_up this_
where
this_.id in (
?
)
有没有人知道正确的方式来筛选标准(Hibernate 3.2)中的一组枚举值?
干杯 西蒙