2015-07-11 51 views
2

您好,我有以下类如何通过示例使用hibernate查询来搜索Id?

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字段我得到确切的响应时,当我试图通过编号搜索我越来越意想不到的结果 我有很多论坛的goggled我无法得到我想要的一些请帮助我 如何处理这个问题?

回答

1

the documentation

版本属性,标识符和关联被忽略。默认情况下,排除空值属性。