Hibernate Criteria示例查询

时间:2013-06-03 09:12:30

标签: hibernate persistence hibernate-criteria

我遇到了Hibernate示例查询的问题。如何使用Hibernate示例查询加入查询。这就是我想要做的事情;

Cat cat = new Cat();
cat.setFood(myFoodObject); // Food is another entity that has reference to Cat class.
List results = session.createCriteria(Cat.class)
.add( Example.create(cat) )
.list();

我的食物课;

public class Food { 
.....
@OneToMany(cascade = CascadeType.ALL,mappedBy = "food", fetch = FetchType.EAGER)
private List<Cat> catList;
}

我的猫班;

public class Cat{
.....
@JoinColumn(name = "food", referencedColumnName = "id")
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
private Food food;
}

1 个答案:

答案 0 :(得分:0)

The documentation for Example queries说:

  

忽略版本属性,标识符和关联

(强调我的)