個別の選択の代わりに JOIN を積極的にロードしたいエンティティへDomain
の@ManyToOne
一方向の関係を持つエンティティがあります。Country
を使おうと思いまし@Fetch
た。
@Entity
@Table
public class Domain {
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
@Column(name = "domain_id")
private Long domainId;
@Fetch(FetchMode.JOIN)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Country country;
...
}
HQL
これらのエンティティを照会するために使用しています。
しかし、Hibernate はフェッチ戦略を適用しません。私は試してみましたが@OneToOne
(私のデザインでは何も変わりません)、それもうまくいきません。SQL 出力の例を次に示します。
Hibernate: select domain0_.domain_id as domain1_2_, domain0_.country as country2_, domain0_.name as name2_, domain0_.type as type2_ from domain domain0_ order by domain0_.name limit ?
Hibernate: select country0_.country_id as country1_1_0_, country0_.code as code1_0_, country0_.currency as currency1_0_, country0_.name as name1_0_ from country country0_ where country0_.country_id=?
Hibernate: select country0_.country_id as country1_1_0_, country0_.code as code1_0_, country0_.currency as currency1_0_, country0_.name as name1_0_ from country country0_ where country0_.country_id=?
Hibernate: select country0_.country_id as country1_1_0_, country0_.code as code1_0_, country0_.currency as currency1_0_, country0_.name as name1_0_ from country country0_ where country0_.country_id=?
Hibernate: select country0_.country_id as country1_1_0_, country0_.code as code1_0_, country0_.currency as currency1_0_, country0_.name as name1_0_ from country country0_ where country0_.country_id=?
Hibernate: select country0_.country_id as country1_1_0_, country0_.code as code1_0_, country0_.currency as currency1_0_, country0_.name as name1_0_ from country country0_ where country0_.country_id=?
何かが適用を妨げていると思います。それは何ですか?