java - hibernate 标准过滤一组枚举值

标签 java sql mysql hibernate enums

您好,我正在使用带 1.6 JDK 和 Mysql 5.0 的 Hibernate 3.2 我正在尝试使用标准 api 来组合动态过滤器。但是,当我在作为我的 Criteria 对象属性的一组枚举上添加限制时,我得到了 org.hibernate.exception.GenericJDBCException。

我的代码是这样的:

public class FollowUp {
    ...
    public Set<AdminCategory> getAdminCategories() {...}
    public void setAdminCategories(Set<AdminCategory> _arg) { ... }

}

我的 hibernate 映射文件有一组在 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 中)中过滤一组枚举值的正确方法?

干杯 西蒙

最佳答案

您似乎传递了不兼容的参数类型。例如,它需要很长时间,但您传递了 int。将您的日志级别设置为跟踪并查看 hibernate 期望什么,以便您可以决定传递数组或集合或其他内容。

关于java - hibernate 标准过滤一组枚举值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967199/

相关文章:

java - 初学者我的方法有什么问题

java - 显示对象的图形

mysql - Codeigniter SUM 和 LEFT JOIN 同时删除重复项

sql - 如何使用 NuoDB 在 Ruby On Rails 中手动执行 SQL 命令

php - 获取两列中具有相同值的行数据

php - 检查 SQL 数据库中不存在的值

java - 如何使用 java SDK 在 token 过期后重新连接到 QBO API

java - 数组中的值未分配 - java

sql - 如何限制 oracle number(10) 数据类型的最大值为 2147483647

mysql - 选择并比较来自不同数据库的 2 个表