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.
This commit is contained in:
Oliver Gierke
2014-04-22 14:29:15 +02:00
parent aff479d4a4
commit e32e724fc8

View File

@@ -210,11 +210,15 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
Assert.notNull(id, "The given id must not be null!");
Class<T> domainType = getDomainClass();
if (crudMethodMetadata == null) {
return em.find(domainType, id);
}
LockModeType type = crudMethodMetadata.getLockModeType();
Map<String, Object> hints = crudMethodMetadata.getQueryHints();
Class<T> domainType = getDomainClass();
return type == null ? em.find(domainType, id, hints) : em.find(domainType, id, type, hints);
}
@@ -525,6 +529,10 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
private TypedQuery<T> applyRepositoryMethodMetadata(TypedQuery<T> query) {
if (crudMethodMetadata == null) {
return query;
}
LockModeType type = crudMethodMetadata.getLockModeType();
TypedQuery<T> toReturn = type == null ? query : query.setLockMode(type);