嗨我使用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)中的一組枚舉值?
乾杯 西蒙