From 9d3c19f7000cac71b3c248edf801e7c27f139135 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 5 Sep 2017 13:18:10 +0200 Subject: [PATCH] DATAJPA-1175 - Remove EntityManager injection in QuerydslRepositorySupport. We no longer declare entity manager injection in QuerydslRepositorySupport to prevent annotation-triggered class path scanning from touching this class. Class path scans can fail because Querydsl is an optional dependency and @PersistenceContext is a marker for environments like CDI to initiate a class path scan. Depending on the scan implementation, reflection-based scanners are known to fail because the class cannot be linked without Querydsl on the class path. We decided to remove injection entirely to move the injection responsibility to code building upon QuerydslRepositorySupport. Using Autowired would work only in Spring environments and not pure Java EE environments (EJB, CDI). Using @Inject would cause the same effect as @PersistenceContext. --- .../jpa/repository/support/QuerydslRepositorySupport.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslRepositorySupport.java b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslRepositorySupport.java index d3c0ac209..d41997f98 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslRepositorySupport.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslRepositorySupport.java @@ -18,7 +18,6 @@ package org.springframework.data.jpa.repository.support; import javax.annotation.Nullable; import javax.annotation.PostConstruct; import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; import org.springframework.util.Assert; @@ -33,8 +32,8 @@ import com.querydsl.jpa.impl.JPADeleteClause; import com.querydsl.jpa.impl.JPAUpdateClause; /** - * Base class for implementing repositories using QueryDsl library. - * + * Base class for implementing repositories using Querydsl library. + * * @author Oliver Gierke * @author Mark Paluch */ @@ -60,9 +59,8 @@ public abstract class QuerydslRepositorySupport { /** * Setter to inject {@link EntityManager}. * - * @param entityManager must not be {@literal null} + * @param entityManager must not be {@literal null}. */ - @PersistenceContext public void setEntityManager(EntityManager entityManager) { Assert.notNull(entityManager, "EntityManager must not be null!");