In springboot 3.3.x, a with clause supports delete operations - e.g.
@Transactional
@Modifying
@Query(nativeQuery = true,
value = """
with to_delete as (select id from person where birthday < :birthday)
delete from person where id in (select id from to_delete)
""")
int deleteByBirthday(@Param("birthday") Date birthday);
In springboot 3.4.x, this same query generates the following error
Syntax error in SQL statement "with to_delete as (select id from person where birthday < ?)\000a [*]delete from person where id in (select id from to_delete)\000a"; expected ",, (, SELECT, TABLE, VALUES"; SQL statement: with to_delete as (select id from person where birthday < ?) delete from person where id in (select id from to_delete)
The attach sample project shows the issue - just change the springboot version in the pom
In my real world scenario I use this form of query in a loop where I also add an order by and limit clause so I do not overload my DB trying to delete 1000s of rows.
Comment From: wilkinsona
Thanks for the report and sample but Spring Boot does not deal with processing of a Spring Data JPA @Query
. This will either be a Spring Data JPA problem or a Hibernate problem. Spring Boot 3.3.9 uses Hibernate 6.5.3.Final while Spring Boot 3.4.3 uses Hibernate 6.6.8.Final. Using Spring Boot 3.4.3 with Hibernate 6.5.3 results in the same failure so this would appear to be a Spring Data JPA problem. Please raise an issue over there.