From 87ff7a6bdc375d7f989e337afd1ae28ea36f72df 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 294a117ad..e8836066b 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 @@ -17,7 +17,6 @@ package org.springframework.data.jpa.repository.support; import javax.annotation.PostConstruct; import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; import org.springframework.util.Assert; @@ -32,8 +31,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 */ @@ -59,9 +58,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!");