人! 私は多対多のHibernate - ManyToMany subはLEFT JOIN FETCHを選択します
public class ExhibitorList {
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="exhibitor_layouts",
[email protected](name="exhibitor_list_id"),
[email protected](name="layout_id"))
private List<Layout> layouts = new ArrayList<>();
}
そして
public class Layout {
@ManyToMany(mappedBy="layouts",fetch=FetchType.EAGER)
private List<ExhibitorList> exhibitor = new ArrayList<>();
}
私はエンティティを取得するためにHPQを使用している関係で二つのクラス2つのプロパティを持っています。
final String FIND_ALL_JOIN = "SELECT ex from ExhibitorList as ex LEFT join FETCH ex.layouts order by ex.id";
@Query(FIND_ALL_JOIN)
List<ExhibitorList> findAllJoin();
問題は、このクエリは、私はレイアウトを持っている6社の出展があり、現時点では(レイアウトを持つ任意の出展のために副選択を取得していることである。
Hibernate: select exhibitorl0_.id as id1_6_0_, layout2_.id as id1_8_1_, exhibitorl0_.catalogue_number as catalogu2_6_0_, exhibitorl0_.exhibitor_name as exhibito3_6_0_, exhibitorl0_.exhibitor_price as exhibito4_6_0_, exhibitorl0_.oracle_number as oracle_n5_6_0_, layout2_.created as created2_8_1_, layout2_.name as name3_8_1_, layout2_.status as status4_8_1_, layouts1_.exhibitor_list_id as exhibito1_5_0__, layouts1_.layout_id as layout_i2_5_0__ from exhibitor_list exhibitorl0_ left outer join exhibitor_layouts layouts1_ on exhibitorl0_.id=layouts1_.exhibitor_list_id left outer join layout layout2_ on layouts1_.layout_id=layout2_.id order by exhibitorl0_.id
Hibernate: select exhibitor0_.layout_id as layout_i2_5_0_, exhibitor0_.exhibitor_list_id as exhibito1_5_0_, exhibitorl1_.id as id1_6_1_, exhibitorl1_.catalogue_number as catalogu2_6_1_, exhibitorl1_.exhibitor_name as exhibito3_6_1_, exhibitorl1_.exhibitor_price as exhibito4_6_1_, exhibitorl1_.oracle_number as oracle_n5_6_1_ from exhibitor_layouts exhibitor0_ inner join exhibitor_list exhibitorl1_ on exhibitor0_.exhibitor_list_id=exhibitorl1_.id where exhibitor0_.layout_id=?
Hibernate: select exhibitor0_.layout_id as layout_i2_5_0_, exhibitor0_.exhibitor_list_id as exhibito1_5_0_, exhibitorl1_.id as id1_6_1_, exhibitorl1_.catalogue_number as catalogu2_6_1_, exhibitorl1_.exhibitor_name as exhibito3_6_1_, exhibitorl1_.exhibitor_price as exhibito4_6_1_, exhibitorl1_.oracle_number as oracle_n5_6_1_ from exhibitor_layouts exhibitor0_ inner join exhibitor_list exhibitorl1_ on exhibitor0_.exhibitor_list_id=exhibitorl1_.id where exhibitor0_.layout_id=?
Hibernate: select exhibitor0_.layout_id as layout_i2_5_0_, exhibitor0_.exhibitor_list_id as exhibito1_5_0_, exhibitorl1_.id as id1_6_1_, exhibitorl1_.catalogue_number as catalogu2_6_1_, exhibitorl1_.exhibitor_name as exhibito3_6_1_, exhibitorl1_.exhibitor_price as exhibito4_6_1_, exhibitorl1_.oracle_number as oracle_n5_6_1_ from exhibitor_layouts exhibitor0_ inner join exhibitor_list exhibitorl1_ on exhibitor0_.exhibitor_list_id=exhibitorl1_.id where exhibitor0_.layout_id=?
Hibernate: select exhibitor0_.layout_id as layout_i2_5_0_, exhibitor0_.exhibitor_list_id as exhibito1_5_0_, exhibitorl1_.id as id1_6_1_, exhibitorl1_.catalogue_number as catalogu2_6_1_, exhibitorl1_.exhibitor_name as exhibito3_6_1_, exhibitorl1_.exhibitor_price as exhibito4_6_1_, exhibitorl1_.oracle_number as oracle_n5_6_1_ from exhibitor_layouts exhibitor0_ inner join exhibitor_list exhibitorl1_ on exhibitor0_.exhibitor_list_id=exhibitorl1_.id where exhibitor0_.layout_id=?
Hibernate: select exhibitor0_.layout_id as layout_i2_5_0_, exhibitor0_.exhibitor_list_id as exhibito1_5_0_, exhibitorl1_.id as id1_6_1_, exhibitorl1_.catalogue_number as catalogu2_6_1_, exhibitorl1_.exhibitor_name as exhibito3_6_1_, exhibitorl1_.exhibitor_price as exhibito4_6_1_, exhibitorl1_.oracle_number as oracle_n5_6_1_ from exhibitor_layouts exhibitor0_ inner join exhibitor_list exhibitorl1_ on exhibitor0_.exhibitor_list_id=exhibitorl1_.id where exhibitor0_.layout_id=?
私が計画して使用する場合のfindAllと春データ() ;例えば、私はN + 1つの問題を取得
1とレイアウトのすべての出展者を取得する方法
いいえ...これは返さないので、これは私の論理を壊しますList ... –
Rostislav
Yes is is returns出展者リストアップデートをチェックする。 –