Hibernate 标准示例

Hibernate Criteria by Examle

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

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

但是也行不通。我知道我可以使用限制或 HQL,但我想尝试这样做。 如何正确使用Examle?

来自the documentation

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