我遇到了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;
}