如何通过示例使用hibernate查询来搜索Id? [英] how to search an Id using hibernate query by example?
问题描述
我有以下班级
hi i have the following class
public class Label
{
private Long TableId;
private Long Id;
private String LabelName;
//getters and setters for corresponding fields
}
我应该动态搜索多个字段
i通过示例发现了hibernate查询构造我的代码看起来像是一些东西
i was supposed to search on multiple fields dynamically i came across hibernate query by example construct my code looks like some thing
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搜索我得到意想不到的结果
i有goggled许多论坛我无法得到我想要的一些请帮助我
如何处理这个问题?
when i'm searching on LabelName field i'm getting the exact response when when i tried to search by id i'm getting unexpected results i have goggled many forums i couldn't get what i want some one please help me how to deal with this issue?
推荐答案
From 文档
$ b
From the documentation
版本属性,标识符和关联被忽略。默认情况下,排除空值属性。
Version properties, identifiers and associations are ignored. By default, null valued properties are excluded.
这篇关于如何通过示例使用hibernate查询来搜索Id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!