条件api--root.fectch()如何获取集合? [英] criteria api--root.fectch() how to fetch a collection?
本文介绍了条件api--root.fectch()如何获取集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
args的方法fetch()类型可以是SingularAttribute,PluralAttribute,为什么不能不能是ListAttribute?
The args' type of method fetch() can be SingularAttribute, PluralAttribute, why not can't be ListAttribute ?
然后,如何使用critria来获取集合api?谢谢。
Then, how to fetch a collection with critria api ? Thank you.
推荐答案
当然可以,正如Rasmus Franke所说。只需从用于FetchParent的javadocs中检查
或尝试以下操作:
Of course it can, as Rasmus Franke said. Just check from the javadocs for FetchParent or try this:
@Entity
public class SomeEntity {
@Id int id;
@OneToMany List<OtherEntity> others;
}
@Entity
public class OtherEntity {
@Id int id;
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SomeEntity> cq = cb.createQuery(SomeEntity.class);
Root<SomeEntity> root = cq.from(SomeEntity.class);
ListAttribute<? super SomeEntity, OtherEntity> listAttribute = root.getModel().getList("others", OtherEntity.class);
root.fetch(listAttribute, JoinType.LEFT);
cq.select(root);
这篇关于条件api--root.fectch()如何获取集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文