0
我有一個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();
my food class;
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;
}