Examle的Hibernate标准

时间:2016-03-29 11:10:10

标签: hibernate criteria query-by-example

我正在尝试通过示例创建Criteria。但是我得到了不同Example对象的相同结果。

Author author = new Author();
author.setId(3L);
News news = new News();
news.setAuthor(author);

List<News> newsList = getSession().createCriteria(News.class)
           .add(Example.create(news))
           .list();

如果我更改了ID,那么我会得到相同的新闻列表。 我试着做下一个:

//...
.add(Example.create(news.getAuthor())

但它也不起作用。我知道我可以使用例如Restrictions或HQL,但我想尝试这样做。 如何正确使用Examle?

1 个答案:

答案 0 :(得分:1)

来自the documentation

  

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