0
少しばかげた質問ですが、なぜ動作しないのか分かりません。私の目標は、子どもがいる親のリストを取得することです(1回のリクエストで)。私は適切な親オブジェクトを取得しますが、子オブジェクトはそれで取り出されません。jpa/hibernate noob:join fetchが正常に動作しない
エンティティ
@Entity
@Table(name = "parent")
@Data
public class Parent implements Serializable {
...
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parent")
private List<Child> children = new ArrayList<>();
リポジトリ
@Query("select p from Parent p JOIN FETCH p.children child where " +
"(child.date between ?1 and ?2)")
List<Parent> findCustom(@Param("from") @DateTimeFormat(iso = ISO.DATE) Date from, @Param("to") @DateTimeFormat(iso = ISO.DATE) Date to);
更新:ここ
は、要求の結果である{
"_embedded" : {
"parent" : [ {
"name" : "name",
"category" : "UNASSIGNED",
"_links" : {
"self" : {
"href" : "http://localhost:8080/json/parent/10"
},
"parent" : {
"href" : "http://localhost:8080/json/parent/10{?projection}",
"templated" : true
},
"children" : {
"href" : "http://localhost:8080/json/parent/10/children"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/json/parent/search/findCustom?from=2016-01-14T07:35+0000&to=2017-01-14T07:35+0000"
}
}
}
これを試してみてください。ここでの実際の質問は何ですか?何が問題ですか? – Tobb
問題は、私は子供がいない親だけを取得することです、私の目標はそれにカプセル化された子オブジェクトを持つ親を取得することです – user3287019
だから子供のリストは空ですか?あるいは、あなたは0人の子供を持っている親を得るだけですか?いずれの場合も、フェッチ結合とは関係ありません。 – Tobb