1

When using constructor injection, what is the correct way of injecting the persistence context ?

Both of these solution makes my integration test pass, so looks like EntityManager is injected correctly, but I am not sure about the difference.

@AllArgsConstructor
@Service
@Slf4j
public class StockService {

    private StockRepo stockRepo;
    private IndexRepo indexRepo;
    private EntityManager entityManager;
...
}

or

@AllArgsConstructor
@Service
@Slf4j
public class StockService {

    private StockRepo stockRepo;
    private IndexRepo indexRepo;
    @PersistenceContext
    private EntityManager entityManager;
...
}
GionJh
  • 2,742
  • 2
  • 29
  • 68

0 Answers0