how to search an Id using hibernate query by example?

北城以北 提交于 2019-12-11 02:06:08

问题


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 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();

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?


回答1:


From the documentation

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



来源:https://stackoverflow.com/questions/31356381/how-to-search-an-id-using-hibernate-query-by-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!