During migration from spring boot 2 to 3 we found different behavior between Hibernate 5 and 6. We are using Entity graph and Specification (Criteria). We implemented a small application with which we tested Hibernate 5 and Hibernate 6.
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(root.join("environment").get("name")), "%Test%"));
criteriaQuery.distinct(true).where(predicates.toArray(new Predicate[0]));
TypedQuery<DeploymentJob> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setHint("jakarta.persistence.fetchgraph", entityGraph);
SQL generated by Hibernate 5:
select
distinct deployment0_.id as id1_0_0_,
environmen1_.id as id1_1_1_,
deployment0_.created_at as created_2_0_0_,
deployment0_.environment_id as environm4_0_0_,
deployment0_.finished_at as finished3_0_0_,
environmen1_.created_at as created_2_1_1_,
environmen1_.modified_at as modified3_1_1_,
environmen1_.name as name4_1_1_,
environmen1_.url as url5_1_1_
from
tff_deployment_job deployment0_
inner join tff_environment environmen1_ on
deployment0_.environment_id = environmen1_.id
where
lower(environmen1_.name) like ?
SQL generated by Hibernate 6:
select
distinct dj1_0.id,
dj1_0.created_at,
dj1_0.environment_id,
e2_0.id,
e2_0.created_at,
e2_0.modified_at,
e2_0.name,
e2_0.url,
dj1_0.finished_at
from
tff_deployment_job dj1_0
join tff_environment e1_0 on
e1_0.id = dj1_0.environment_id
join tff_environment e2_0 on
e2_0.id = dj1_0.environment_id
where
lower(e1_0.name) like ? escape ''
Hibernate 6 generates same join from Criteria also from Entity Graph.
Question: Is it a bug? or is it not possible to use join on column which is used in Entity graph?
Thanks in advance.