I am wondering from where does come this entityManager
via constructor? Why i do not have to use @PersistenceContext
annotation below?
Spring creates this bean via @Repository
annotation.
@Repository
public class RRepositoryCustomImpl {
private final EntityManager entityManager;
@Autowired
public RRepositoryCustomImpl(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
Second option is using @PersistenceContext
annotation:
@Repository
public class ACustomRepository {
@PersistenceContext
private EntityManager entityManager;
}
Why we can define EntityManager without @PersistenceContext annotation in the code example above? What's the difference between this two approaches? From where Spring takes EntityManager in this two scenarios?
Possible duplicate of: @Autowired vs @PersistenceContext for EntityManager bean