@FetchProfile を HQL で動作させることができません。
(古い) ネイティブ Criteria と session.get() API ではうまく使用できましたが、HQL ではうまく使用できませんでした。
正常ですか?
おかげで私のマッピングと FetchProfile 定義
@FetchProfiles({ @FetchProfile( name = "countryCities",
fetchOverrides = { @FetchOverride(entity = Country.class,
association = "cities", mode = FetchMode.JOIN) }) })
public class Country implements java.io.Serializable {
@Id
private long id;
@Version
private int version;
private String country;
@OneToMany(mappedBy = "country")
private Set<City> cities = new HashSet<City>(0);
}
以下は機能しません:
@Override
public List<Country> findAllFetchProfileCities() {
getSession().enableFetchProfile("countryCities");
boolean enabled = getSession().isFetchProfileEnabled("countryCities");
List<Country> list = getSession().createQuery("from Country").list();
enabled = getSession().isFetchProfileEnabled("countryCities");
return list;
}
以下はOKです:
@Override
public Country findOneFetchProfileCities(Long _id) {
getSession().enableFetchProfile("countryCities");
Country c = (Country) getSession().get(Country.class, _id);
return c;
}
@Override
public List<Country> findAllCriteriaFetchProfileCities() {
getSession().enableFetchProfile("countryCities");
return getSession().createCriteria(Country.class).list();
}