Dedicated exception for aggregate roots without id property.
We now distinguish between an id not set during insert and a supposed aggregate root without id property. Closes #1502 Original pull request #1855
This commit is contained in:
@@ -165,6 +165,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
|
||||
Assert.notNull(instance, "Aggregate instance must not be null");
|
||||
|
||||
verifyIdProperty(instance);
|
||||
|
||||
return performSave(new EntityAndChangeCreator<>(instance, changeCreatorSelectorForSave(instance)));
|
||||
}
|
||||
|
||||
@@ -179,6 +181,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
|
||||
List<EntityAndChangeCreator<T>> entityAndChangeCreators = new ArrayList<>();
|
||||
for (T instance : instances) {
|
||||
verifyIdProperty(instance);
|
||||
entityAndChangeCreators.add(new EntityAndChangeCreator<>(instance, changeCreatorSelectorForSave(instance)));
|
||||
}
|
||||
return performSaveAll(entityAndChangeCreators);
|
||||
@@ -425,6 +428,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void verifyIdProperty(T instance) {
|
||||
// accessing the id property just to raise an exception in the case it does not exist.
|
||||
context.getRequiredPersistentEntity(instance.getClass()).getRequiredIdProperty();
|
||||
}
|
||||
|
||||
private <T> void doDeleteAll(Iterable<? extends T> instances, Class<T> domainType) {
|
||||
|
||||
BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange
|
||||
|
||||
Reference in New Issue
Block a user