The bug was introduced by
HHH-9305
.
Example: Tree entities with OneToOne association: person <
> address <
> country
We are using JPA criteria that's why we cannot use fetch in the where clause. So we are doing the following:
select persion
from Persion as persion
inner join persion.address as address_filter
inner join fetch persion.address as address
inner join fetch address.country
where
address_filter.city_name = 'some value';
After
HHH-9305
changes it reuses the first fetch and query (during parsing) is become as this:
select persion
from Persion as persion
inner join persion.address as address_filter
inner join fetch address.country
where
address_filter.city_name = 'some value'
Because it cannot found parent for country fetch it throws an error: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
Since I cannot imagine a case where I need to do join twice in OneToOne associations except for fetching I think it's ok to reuse join here but for this case it should be the second join (with fetch option).
I have found a good workaround.
select persion
from Persion as persion
inner join fetch persion.address as address
inner join fetch address.country
where
persion.address.city_name = 'some value';
This query can be converted to JPA criteria query and will do exactly the same thing without any errors.
|