diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index e9a2d4b20..98d839b64 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -99,7 +99,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation entityInformation; - private final EntityManager em; + private final EntityManager entityManager; private final PersistenceProvider provider; private @Nullable CrudMethodMetadata metadata; @@ -117,7 +117,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation domainClass, EntityManager em) { - this(JpaEntityInformationSupport.getEntityInformation(domainClass, em), em); + public SimpleJpaRepository(Class domainClass, EntityManager entityManager) { + this(JpaEntityInformationSupport.getEntityInformation(domainClass, entityManager), entityManager); } /** @@ -188,14 +188,14 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation type = ProxyUtils.getUserClass(entity); - T existing = (T) em.find(type, entityInformation.getId(entity)); + T existing = (T) entityManager.find(type, entityInformation.getId(entity)); // if the entity to be deleted doesn't exist, delete is a NOOP if (existing == null) { return; } - em.remove(em.contains(entity) ? entity : em.merge(entity)); + entityManager.remove(entityManager.contains(entity) ? entity : entityManager.merge(entity)); } @Override @@ -230,7 +230,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation domainType = getDomainClass(); if (metadata == null) { - return Optional.ofNullable(em.find(domainType, id)); + return Optional.ofNullable(entityManager.find(domainType, id)); } LockModeType type = metadata.getLockModeType(); Map hints = getHints(); - return Optional.ofNullable(type == null ? em.find(domainType, id, hints) : em.find(domainType, id, type, hints)); + return Optional.ofNullable(type == null ? entityManager.find(domainType, id, hints) : entityManager.find(domainType, id, type, hints)); } @Deprecated @@ -332,7 +333,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation idAttributeNames = entityInformation.getIdAttributeNames(); String existsQuery = QueryUtils.getExistsQueryString(entityName, placeholder, idAttributeNames); - TypedQuery query = em.createQuery(existsQuery, Long.class); + TypedQuery query = entityManager.createQuery(existsQuery, Long.class); applyQueryHints(query); @@ -456,20 +457,20 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation spec) { - CriteriaQuery cq = this.em.getCriteriaBuilder() // + CriteriaQuery cq = this.entityManager.getCriteriaBuilder() // .createQuery(Integer.class) // - .select(this.em.getCriteriaBuilder().literal(1)); + .select(this.entityManager.getCriteriaBuilder().literal(1)); applySpecificationToCriteria(spec, getDomainClass(), cq); - TypedQuery query = applyRepositoryMethodMetadata(this.em.createQuery(cq)); + TypedQuery query = applyRepositoryMethodMetadata(this.entityManager.createQuery(cq)); return query.setMaxResults(1).getResultList().size() == 1; } @Override public long delete(Specification spec) { - CriteriaBuilder builder = this.em.getCriteriaBuilder(); + CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); CriteriaDelete delete = builder.createCriteriaDelete(getDomainClass()); if (spec != null) { @@ -480,7 +481,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation scrollDelegate = new SpecificationScrollDelegate<>(scrollFunction, entityInformation); FetchableFluentQuery fluentQuery = new FetchableFluentQueryBySpecification<>(spec, domainClass, finder, - scrollDelegate, this::count, this::exists, this.em); + scrollDelegate, this::count, this::exists, this.entityManager); return queryFunction.apply((FetchableFluentQuery) fluentQuery); } @@ -549,13 +550,13 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation boolean exists(Example example) { Specification spec = new ExampleSpecification<>(example, this.escapeCharacter); - CriteriaQuery cq = this.em.getCriteriaBuilder() // + CriteriaQuery cq = this.entityManager.getCriteriaBuilder() // .createQuery(Integer.class) // - .select(this.em.getCriteriaBuilder().literal(1)); + .select(this.entityManager.getCriteriaBuilder().literal(1)); applySpecificationToCriteria(spec, example.getProbeType(), cq); - TypedQuery query = applyRepositoryMethodMetadata(this.em.createQuery(cq)); + TypedQuery query = applyRepositoryMethodMetadata(this.entityManager.createQuery(cq)); return query.setMaxResults(1).getResultList().size() == 1; } @@ -595,7 +596,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation query = em.createQuery(getCountQueryString(), Long.class); + TypedQuery query = entityManager.createQuery(getCountQueryString(), Long.class); applyQueryHintsForCount(query); @@ -614,10 +615,10 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation TypedQuery getQuery(@Nullable Specification spec, Class domainClass, Sort sort) { - CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(domainClass); Root root = applySpecificationToCriteria(spec, domainClass, query); @@ -752,7 +753,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation TypedQuery getCountQuery(@Nullable Specification spec, Class domainClass) { - CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(Long.class); Root root = applySpecificationToCriteria(spec, domainClass, query); @@ -788,7 +789,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation hints = new HashMap<>(); - getQueryHints().withFetchGraphs(em).forEach(hints::put); + getQueryHints().withFetchGraphs(entityManager).forEach(hints::put); if (metadata != null) { applyComment(metadata, hints::put);