org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; when trying to delete entities

Description

We have an issue when we tried to upgrade our springboot from 2.1.0 to 2.2.0
After posting in spring-boot github issues: https://github.com/spring-projects/spring-boot/issues/22599
and then into Spring JPA project: https://jira.spring.io/browse/DATAJPA-1763 I ended up here, which is perhaps where I should've started.

We are trying to update our springboot application from 2.1.0 to 2.3.2

All goes good except for some specific queries that we have. Our queries work up until 2.1.16, but not on 2.2.0

Our query is as following: 

 

For springboot <= 2.1.16 that works.
For springboot >= 2.2.0 it throws:

 

I tried to read the release notes of 2.2.0 here, but I cannot find anything related to this, thus I think it might be a bug. Now I know based on Mark Paluch's answer that that Spring Boot 2.1 was using Hibernate 5.3 while Boot 2.2 has upgraded to Hibernate 5.4. (source)

When I run both versions (2.1.16 and 2.2.0) with `spring.jpa.show-sql=true` I can see it produces different queries:

2.1.16:

2.2.0:

 

 

Minimal setup to replicate the issue is as following:

MainTable:

 

 

 

 

Special:

 

 

 

 MainTableRepository:

 

SpecialRepository:

 

Test:

 

test application.properties:

 

pom.xml:

That test passes when ran with the lower version of springboot, but fails with 2.2.0, 2.2.9, 2.3.0 and 2.3.2 

This is the full exception:

 

Environment

None

Assignee

Unassigned

Reporter

Nikola Hrusov

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.3.17

Components

Affects versions

Priority

Critical
Configure