DATAJPA-1535 - Make sure we resolve proxy types in optimized SimpleJpaRepository.delete(…).

We now properly lookup the actual user type in case proxy instances are handed into SimpleJpaRepository.delete(…) which might occur if other aggregates hold a direct reference to the one eventually handed into delete(…).
This commit is contained in:
Oliver Drotbohm
2019-07-18 15:02:25 +02:00
parent 3b00102514
commit 9807bda11f

View File

@@ -53,6 +53,7 @@ import org.springframework.data.jpa.repository.query.EscapeCharacter;
import org.springframework.data.jpa.repository.query.QueryUtils;
import org.springframework.data.jpa.repository.support.QueryHints.NoHints;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.data.util.ProxyUtils;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -188,7 +189,9 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
return;
}
T existing = (T) em.find(entity.getClass(), entityInformation.getId(entity));
Class<?> type = ProxyUtils.getUserClass(entity);
T existing = (T) em.find(type, entityInformation.getId(entity));
// if the entity to be deleted doesn't exist, delete is a NOOP
if (existing == null) {