Ever since we upgraded from Hibernate 5.3 to 5.4, the generated SQL of Spring Data JPA queries which were annotated with Entity Graphs keeps changing between different runs (not deterministic).
The order of the selected columns changes and also the order of the joins.
Is this expected behaviour? If it is, is there any way we can make it deterministic? Because we are using this on test assertions.
Example:
@NamedEntityGraph(
name = "installation-with-connectedcomponents",
attributeNodes = {
@NamedAttributeNode("pressureChambers"),
@NamedAttributeNode("coolingUnits"),
@NamedAttributeNode("cleaningUnits")
})
public class Installation {
@OneToMany(mappedBy = "installation", fetch = FetchType.LAZY)
private Set<PressureChamber> pressureChambers = new HashSet<>();
@OneToMany(mappedBy = "installation", fetch = FetchType.LAZY)
private Set<CoolingUnit> coolingUnits = new HashSet<>();
@OneToMany(mappedBy = "installation", fetch = FetchType.LAZY)
private Set<CleaningUnit> cleaningUnits = new HashSet<>();
}
@EntityGraph("installation-with-connectedcomponents")
@Query("SELECT i FROM Installation i WHERE i.id = :id")
Optional<Installation> findById(UUID id);
In an execution we get:
select installati0_.id
pressurech1_.id
cleaningun2_.id
coolinguni3_.id
installati0_.create_date_time
installati0_.update_date_time
installati0_.name
pressurech1_.create_date_time
cleaningun2_.create_date_time
coolinguni3_.create_date_time
from installation installati0_ left outer join pressure_chamber pressurech1_ on installati0_.id=pressurech1_.installation_id left outer join cleaning_unit cleaningun2_ on installati0_.id=cleaningun2_.installation_id left outer join cooling_unit coolinguni3_ on installati0_.id=coolinguni3_.installation_id where installati0_.id=?
And in another we might get:
select installati0_.id
coolinguni1_.id
cleaningun2_.id
pressurech3_.id
installati0_.create_date_time
installati0_.update_date_time
installati0_.name
coolinguni1_.create_date_time
cleaningun2_.create_date_time
pressurech3_.create_date_time
from installation installati0_ left outer join cooling_unit coolinguni1_ on installati0_.id=coolinguni1_.installation_id left outer join cleaning_unit cleaningun2_ on installati0_.id=cleaningun2_.installation_id left outer join pressure_chamber pressurech3_ on installati0_.id=pressurech3_.installation_id where installati0_.id=?