@@ -94,7 +94,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
9494 private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null" ;
9595
9696 private final JpaEntityInformation <T , ?> entityInformation ;
97- private final EntityManager em ;
97+ private final EntityManager entityManager ;
9898 private final PersistenceProvider provider ;
9999
100100 private @ Nullable CrudMethodMetadata metadata ;
@@ -112,18 +112,18 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
112112 Assert .notNull (entityManager , "EntityManager must not be null" );
113113
114114 this .entityInformation = entityInformation ;
115- this .em = entityManager ;
115+ this .entityManager = entityManager ;
116116 this .provider = PersistenceProvider .fromEntityManager (entityManager );
117117 }
118118
119119 /**
120120 * Creates a new {@link SimpleJpaRepository} to manage objects of the given domain type.
121121 *
122122 * @param domainClass must not be {@literal null}.
123- * @param em must not be {@literal null}.
123+ * @param entityManager must not be {@literal null}.
124124 */
125- public SimpleJpaRepository (Class <T > domainClass , EntityManager em ) {
126- this (JpaEntityInformationSupport .getEntityInformation (domainClass , em ), em );
125+ public SimpleJpaRepository (Class <T > domainClass , EntityManager entityManager ) {
126+ this (JpaEntityInformationSupport .getEntityInformation (domainClass , entityManager ), entityManager );
127127 }
128128
129129 /**
@@ -183,14 +183,14 @@ public void delete(T entity) {
183183
184184 Class <?> type = ProxyUtils .getUserClass (entity );
185185
186- T existing = (T ) em .find (type , entityInformation .getId (entity ));
186+ T existing = (T ) entityManager .find (type , entityInformation .getId (entity ));
187187
188188 // if the entity to be deleted doesn't exist, delete is a NOOP
189189 if (existing == null ) {
190190 return ;
191191 }
192192
193- em .remove (em .contains (entity ) ? entity : em .merge (entity ));
193+ entityManager .remove (entityManager .contains (entity ) ? entity : entityManager .merge (entity ));
194194 }
195195
196196 @ Override
@@ -225,7 +225,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
225225 String queryString = String .format (DELETE_ALL_QUERY_BY_ID_STRING , entityInformation .getEntityName (),
226226 entityInformation .getIdAttribute ().getName ());
227227
228- Query query = em .createQuery (queryString );
228+ Query query = entityManager .createQuery (queryString );
229229
230230 /*
231231 * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already.
@@ -266,7 +266,8 @@ public void deleteAllInBatch(Iterable<T> entities) {
266266 return ;
267267 }
268268
269- applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities , em )
269+ applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities ,
270+ entityManager )
270271 .executeUpdate ();
271272 }
272273
@@ -283,7 +284,7 @@ public void deleteAll() {
283284 @ Transactional
284285 public void deleteAllInBatch () {
285286
286- Query query = em .createQuery (getDeleteAllQueryString ());
287+ Query query = entityManager .createQuery (getDeleteAllQueryString ());
287288
288289 applyQueryHints (query );
289290
@@ -298,13 +299,13 @@ public Optional<T> findById(ID id) {
298299 Class <T > domainType = getDomainClass ();
299300
300301 if (metadata == null ) {
301- return Optional .ofNullable (em .find (domainType , id ));
302+ return Optional .ofNullable (entityManager .find (domainType , id ));
302303 }
303304
304305 LockModeType type = metadata .getLockModeType ();
305306 Map <String , Object > hints = getHints ();
306307
307- return Optional .ofNullable (type == null ? em .find (domainType , id , hints ) : em .find (domainType , id , type , hints ));
308+ return Optional .ofNullable (type == null ? entityManager .find (domainType , id , hints ) : entityManager .find (domainType , id , type , hints ));
308309 }
309310
310311 @ Deprecated
@@ -327,7 +328,7 @@ public T getById(ID id) {
327328 public T getReferenceById (ID id ) {
328329
329330 Assert .notNull (id , ID_MUST_NOT_BE_NULL );
330- return em .getReference (getDomainClass (), id );
331+ return entityManager .getReference (getDomainClass (), id );
331332 }
332333
333334 @ Override
@@ -344,7 +345,7 @@ public boolean existsById(ID id) {
344345 Iterable <String > idAttributeNames = entityInformation .getIdAttributeNames ();
345346 String existsQuery = QueryUtils .getExistsQueryString (entityName , placeholder , idAttributeNames );
346347
347- TypedQuery <Long > query = em .createQuery (existsQuery , Long .class );
348+ TypedQuery <Long > query = entityManager .createQuery (existsQuery , Long .class );
348349
349350 applyQueryHints (query );
350351
@@ -470,13 +471,13 @@ public <S extends T> long count(Example<S> example) {
470471 public <S extends T > boolean exists (Example <S > example ) {
471472
472473 Specification <S > spec = new ExampleSpecification <>(example , this .escapeCharacter );
473- CriteriaQuery <Integer > cq = this .em .getCriteriaBuilder () //
474+ CriteriaQuery <Integer > cq = this .entityManager .getCriteriaBuilder () //
474475 .createQuery (Integer .class ) //
475- .select (this .em .getCriteriaBuilder ().literal (1 ));
476+ .select (this .entityManager .getCriteriaBuilder ().literal (1 ));
476477
477478 applySpecificationToCriteria (spec , example .getProbeType (), cq );
478479
479- TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .em .createQuery (cq ));
480+ TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .entityManager .createQuery (cq ));
480481 return query .setMaxResults (1 ).getResultList ().size () == 1 ;
481482 }
482483
@@ -565,7 +566,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
565566 @ Override
566567 public long count () {
567568
568- TypedQuery <Long > query = em .createQuery (getCountQueryString (), Long .class );
569+ TypedQuery <Long > query = entityManager .createQuery (getCountQueryString (), Long .class );
569570
570571 applyQueryHintsForCount (query );
571572
@@ -584,10 +585,10 @@ public <S extends T> S save(S entity) {
584585 Assert .notNull (entity , "Entity must not be null" );
585586
586587 if (entityInformation .isNew (entity )) {
587- em .persist (entity );
588+ entityManager .persist (entity );
588589 return entity ;
589590 } else {
590- return em .merge (entity );
591+ return entityManager .merge (entity );
591592 }
592593 }
593594
@@ -629,7 +630,7 @@ public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities) {
629630 @ Transactional
630631 @ Override
631632 public void flush () {
632- em .flush ();
633+ entityManager .flush ();
633634 }
634635
635636 /**
@@ -712,7 +713,7 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) {
712713 */
713714 protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
714715
715- CriteriaBuilder builder = em .getCriteriaBuilder ();
716+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
716717 CriteriaQuery <S > query = builder .createQuery (domainClass );
717718
718719 Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -722,7 +723,7 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
722723 query .orderBy (toOrders (sort , root , builder ));
723724 }
724725
725- return applyRepositoryMethodMetadata (em .createQuery (query ));
726+ return applyRepositoryMethodMetadata (entityManager .createQuery (query ));
726727 }
727728
728729 /**
@@ -744,7 +745,7 @@ protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
744745 */
745746 protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
746747
747- CriteriaBuilder builder = em .getCriteriaBuilder ();
748+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
748749 CriteriaQuery <Long > query = builder .createQuery (Long .class );
749750
750751 Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -758,7 +759,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
758759 // Remove all Orders the Specifications might have applied
759760 query .orderBy (Collections .emptyList ());
760761
761- return applyRepositoryMethodMetadataForCount (em .createQuery (query ));
762+ return applyRepositoryMethodMetadataForCount (entityManager .createQuery (query ));
762763 }
763764
764765 /**
@@ -795,7 +796,7 @@ private <S, U extends T> Root<U> applySpecificationToCriteria(@Nullable Specific
795796 return root ;
796797 }
797798
798- CriteriaBuilder builder = em .getCriteriaBuilder ();
799+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
799800 Predicate predicate = spec .toPredicate (root , query , builder );
800801
801802 if (predicate != null ) {
@@ -825,7 +826,7 @@ private void applyQueryHints(Query query) {
825826 return ;
826827 }
827828
828- getQueryHints ().withFetchGraphs (em ).forEach (query ::setHint );
829+ getQueryHints ().withFetchGraphs (entityManager ).forEach (query ::setHint );
829830 applyComment (metadata , query ::setHint );
830831 }
831832
@@ -854,7 +855,7 @@ private Map<String, Object> getHints() {
854855
855856 Map <String , Object > hints = new HashMap <>();
856857
857- getQueryHints ().withFetchGraphs (em ).forEach (hints ::put );
858+ getQueryHints ().withFetchGraphs (entityManager ).forEach (hints ::put );
858859
859860 if (metadata != null ) {
860861 applyComment (metadata , hints ::put );
0 commit comments