Derived delete query in Spring Data JDBC not working

Viewed 58

I've put a derived query on a CrudRepository<Customer, Long> that should delete all entities with a given businessId (which is not the primary key but just another, non-unique column), of which there can be many.

In my SpringDataJdbcTest test, I first save 2 customers with the same businessId.

Then, I want to call the following method on the CrudRepository:

  fun deleteAllByBusinessId(businessId: Long)

But it gives me:

org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expected 1, actual 2

    at org.springframework.dao.support.DataAccessUtils.nullableSingleResult(DataAccessUtils.java:100)
    at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:244)

It seems Spring Data Jdbc first wants to determine if there's a unique entity with that business Id, but of course, there are 2.

Could it be that support for such a derived delete query doesn't work correctly? I use Spring Data JDBC 2.3.5.

1 Answers
Related