-
Notifications
You must be signed in to change notification settings - Fork 1.5k
SimpleJpaRepository.deleteAllByIdInBatch accepts Iterable but JPA requires Collection #2242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I reproduced your issue by writing a tiny bit of test code... @Test // 2242
void deleteAllByIdInBatchViaIterable() {
SampleEntity one = new SampleEntity("one", "eins");
SampleEntity two = new SampleEntity("two", "zwei");
SampleEntity three = new SampleEntity("three", "drei");
repository.saveAll(Arrays.asList(one, two, three));
repository.flush();
Iterable<SampleEntityPK> iterableIds = new IterableStream<>(Stream.of(new SampleEntityPK("one", "eins"), new SampleEntityPK("three", "drei")));
repository
.deleteAllByIdInBatch(iterableIds);
assertThat(repository.findAll()).containsExactly(two);
}
static class IterableStream<T> implements Iterable<T> {
private final Stream<T> stream;
IterableStream(Stream<T> stream) {
this.stream = stream;
}
@Override
public Iterator<T> iterator() {
return this.stream.iterator();
}
} And indeed, it DOES fail here. But the context is a bit more subtle. The place it's failing is inside Hibernate itself. Hibernate clearly expects to receive a However, Spring Data JPA doesn't go directly to Hibernate. Instead, it's leaning on It's true that So this puts us in a gray area. I can see justification that if Hibernate itself is looking for a Altering these signatures would be a breaking change, and so we need to weigh it properly, which is why I'd also like feedback from @schauder and possibly @odrotbohm. |
Shouldn't we just convert an |
Even though Spring Data Commons has deleteAllById(Iterable<ID>), some JPA providers require a Collection<ID> instead. So we need to convert if the incoming argument isn't already. See #2242.
JpaRepository accepts Iterable<ID> for bulk deletes. But some JPA providers require Collection<ID> instead. To avoid breaking any APIs, convert the incoming argument if it's not already a Collection. See #2242.
JpaRepository accepts Iterable<ID> for bulk deletes. But some JPA providers require Collection<ID> instead. To avoid breaking any APIs, convert the incoming argument if it's not already a Collection. See #2242.
JpaRepository accepts Iterable<ID> for bulk deletes. But some JPA providers require Collection<ID> instead. To avoid breaking any APIs, convert the incoming argument if it's not already a Collection. See #2242.
JpaRepository accepts Iterable<ID> for bulk deletes. But some JPA providers require Collection<ID> instead. To avoid breaking any APIs, convert the incoming argument if it's not already a Collection. See #2242.
SpringBoot 2.5.1
SimpleJpaRepository.deleteAllByIdInBatch(Iterable<ID> ids)
acceptsIterable
, but in deepQueryParameterBindingValidator.validate
checking against forCollection
.If calling
SimpleJpaRepository.deleteAllByIdInBatch
withIterable
but this class not implementCollection
we got exception.e.g.:
The text was updated successfully, but these errors were encountered: