java - 如何通过示例使用 hibernate 查询来搜索 Id?

标签 java mysql hibernate query-by-example

嗨,我有以下类(class)

public class Label
    {
    private Long TableId;
    private Long Id;
    private String LabelName;
    //getters and setters for corresponding fields
    }

我应该动态搜索多个字段 我通过示例构造了 hibernate 查询,我的代码看起来像一些东西

Label bean =new Label();
if(Id!=null)
{
       bean.setId(Id);
}
if(LabeName!=null)
{
bean.setLabelName(LabelName)
}
    System.out.println(bean.toString());
            Example exampleObject=Example.create(bean).ignoreCase();
             criteria=currentSessionObj.createCriteria(Label.class).add(exampleObject);
             retObjects=criteria.list();

当我在 LabelName 字段上搜索时,我得到了准确的响应当我尝试按 id 搜索时,我得到了意想不到的结果 我浏览了很多论坛,我无法得到我想要的东西,请帮助我 如何处理这个问题?

最佳答案

来自 the documentation

Version properties, identifiers and associations are ignored. By default, null valued properties are excluded.

关于java - 如何通过示例使用 hibernate 查询来搜索 Id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31356381/

相关文章:

php - 如何创建返回结果集的数组并计算 PHP 中数据库中每个组的不同类型值

java - 在 hibernate 中有效地从数据库加载集合的集合

java - 使用数组实现 Set 类

MySQL 错误 2013 (HY000)

java - 如何使用Junit4进行单元测试?

php - 我无法使用 php 将数据输入数据库

java - Hibernate Annotations,从现有的两个实体创建第三个实体,而不注释已经注释的表

java - 如何根据 JPA Web API 中的类型将 JSON 数据转换为两种 JSON 数组格式

java - 使用 eclipse 导出可运行的 jar

java - Mockito anyListOf : results being overridden with different instances as parameters