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 dd3f996be6
commit 21e25503c7

View File

@@ -57,6 +57,7 @@ import org.springframework.data.jpa.repository.query.JpaEntityGraph;
import org.springframework.data.jpa.repository.query.QueryUtils;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.data.repository.support.PageableExecutionUtils.TotalSupplier;
import org.springframework.data.util.ProxyUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@@ -178,7 +179,9 @@ public class SimpleJpaRepository<T, ID extends Serializable>
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) {