-
Notifications
You must be signed in to change notification settings - Fork 57
Labels
Description
With a @Document or @Edge annotated class having a keyType=KeyType.uuid and therefore an @Id annotated attribute of type UUID a call to CrupRepository.delete() (aka SimpleArangoRepository.delete()) will crash resulting in a ClassCastException as the code casts the identifier to String without any need:
public void delete(final T entity) {
String id = (String) arangoOperations.getConverter().getMappingContext()
.getRequiredPersistentEntity(domainClass).getIdentifierAccessor(entity).getRequiredIdentifier();
arangoOperations.delete(id, defaultDeleteOptions(), domainClass);
}Just removing the cast and declaring id as Object should fix the issue:
public void delete(final T entity) {
Object id = arangoOperations.getConverter().getMappingContext()
.getRequiredPersistentEntity(domainClass).getIdentifierAccessor(entity).getRequiredIdentifier();
arangoOperations.delete(id, defaultDeleteOptions(), domainClass);
}Even better also fix the Spring-Data contract of CrupRepository.delete():
Throws: OptimisticLockingFailureException – [...] Also thrown if the entity is assumed to be present but does not exist in the database.
public void delete(final T entity) {
Object id = arangoOperations.getConverter().getMappingContext()
.getRequiredPersistentEntity(domainClass).getIdentifierAccessor(entity).getRequiredIdentifier();
try {
arangoOperations.delete(id, defaultDeleteOptions(), domainClass);
} catch (DocumentNotFoundException unknown) {
throw new OptimisticLockingFailureException("Non persistent entity", unknown)
}
}