From e32e724fc89e965fa58c7bca098b1a98e5215f4d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 22 Apr 2014 14:29:15 +0200 Subject: [PATCH] DATAJPA-517 - Defensive checks for CrudMethodMetadata in SimpleJpaRepository. As CrudMethodMetadata is an optional dependency of SimpleJpaRepository we need to guard access to it with proper null checks. --- .../jpa/repository/support/SimpleJpaRepository.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 3726fbf57..c68c492ce 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -210,11 +210,15 @@ public class SimpleJpaRepository implements JpaRepos Assert.notNull(id, "The given id must not be null!"); + Class domainType = getDomainClass(); + + if (crudMethodMetadata == null) { + return em.find(domainType, id); + } + LockModeType type = crudMethodMetadata.getLockModeType(); Map hints = crudMethodMetadata.getQueryHints(); - Class domainType = getDomainClass(); - return type == null ? em.find(domainType, id, hints) : em.find(domainType, id, type, hints); } @@ -525,6 +529,10 @@ public class SimpleJpaRepository implements JpaRepos private TypedQuery applyRepositoryMethodMetadata(TypedQuery query) { + if (crudMethodMetadata == null) { + return query; + } + LockModeType type = crudMethodMetadata.getLockModeType(); TypedQuery toReturn = type == null ? query : query.setLockMode(type);