2011-02-17 13 views

答えて

3

もちろん、Rasmus Frankeが言ったように、それは可能です。ただ、javadocs for FetchParent からチェックするか、またはこれを試してみてください。

@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); 
+0

右のかもしれないですこと。私は長い間クエリのための基準apiを書いていない。現在私は常にJPQLを使用しています。ありがとうございました。 –

2

ListAttributeはコレクションに基づく任意の属性と同様に、PluralAttributeを拡張します。実際にroot.fetch(ListAttribute)を使用しようとしましたか?

関連する問題