diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java
index 9b516a845..c4d81acaf 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java
@@ -102,13 +102,21 @@ public interface JdbcAggregateOperations {
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
* this fact will be silently ignored.
*
- *
+ *
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
* @param domainType the type of the aggregate root.
* @param the type of the aggregate root.
*/
void deleteAllById(Iterable> ids, Class domainType);
+ /**
+ * Delete an aggregate identified by its aggregate root.
+ *
+ * @param aggregateRoot to delete. Must not be {@code null}.
+ * @param the type of the aggregate root.
+ */
+ void delete(T aggregateRoot);
+
/**
* Delete an aggregate identified by its aggregate root.
*
@@ -118,8 +126,12 @@ public interface JdbcAggregateOperations {
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
* version attribute of the provided entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
+ * @deprecated since 3.0 use {@link #delete(Object)} instead
*/
- void delete(T aggregateRoot, Class domainType);
+ @Deprecated
+ default void delete(T aggregateRoot, Class domainType) {
+ delete(aggregateRoot);
+ }
/**
* Delete all aggregates of a given type.
@@ -128,6 +140,14 @@ public interface JdbcAggregateOperations {
*/
void deleteAll(Class> domainType);
+ /**
+ * Delete all aggregates identified by their aggregate roots.
+ *
+ * @param aggregateRoots to delete. Must not be {@code null}.
+ * @param the type of the aggregate roots.
+ */
+ void deleteAll(Iterable extends T> aggregateRoots);
+
/**
* Delete all aggregates identified by their aggregate roots.
*
@@ -137,8 +157,12 @@ public interface JdbcAggregateOperations {
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for at least on entity the
* version attribute of the entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
+ * @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
*/
- void deleteAll(Iterable extends T> aggregateRoots, Class domainType);
+ @Deprecated
+ default void deleteAll(Iterable extends T> aggregateRoots, Class domainType) {
+ deleteAll(aggregateRoots);
+ }
/**
* Counts the number of aggregates of a given type.
diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java
index 5d0e30292..791c7c622 100644
--- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java
+++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java
@@ -16,6 +16,7 @@
package org.springframework.data.jdbc.core;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -303,11 +304,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
}
@Override
- public void delete(S aggregateRoot, Class domainType) {
+ public void delete(S aggregateRoot) {
Assert.notNull(aggregateRoot, "Aggregate root must not be null");
- Assert.notNull(domainType, "Domain type must not be null");
+ Class domainType = (Class) aggregateRoot.getClass();
IdentifierAccessor identifierAccessor = context.getRequiredPersistentEntity(domainType)
.getIdentifierAccessor(aggregateRoot);
@@ -353,10 +354,26 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
}
@Override
- public void deleteAll(Iterable extends T> instances, Class domainType) {
+ public void deleteAll(Iterable extends T> instances) {
Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty");
+ Map> groupedByType = new HashMap<>();
+
+ for (T instance : instances) {
+ Class> type = instance.getClass();
+ final List