我有三个实体:
Person
,
Country
和
CountryTranslation
.
人
与一个有关
国家
和
国家
有许多
CountryTranslations
.
我要我的查询同时获取
国家
和
国家翻译
当它得到一个
人
为了避免多个查询。
带来
国家
随着
人
我愿意:
List<Person> persons = (List<Person>) entityManager
.createQuery("SELECT person from Person person " +
"left join fetch person.country")
.getResultList()
这很好,我看到在Hibernate上,它获取的很好,没有执行额外的查询来带来
国家
但带来
国家翻译
它仍然执行额外的查询。然后我试着:
List<Person> persons = (List<Person>) entityManager
.createQuery("SELECT person from Person person " +
"left join fetch person.country " +
"left join fetch person.country.translations")
.getResultList()
我得到了错误:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
正确的方法是什么?
提前谢谢