1

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.

user1100243
  • 21
  • 1
  • 2

1 Answers1

1

You are right, derived delete queries don't work yet. See https://github.com/spring-projects/spring-data-relational/issues/771

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348