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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user