PersistenceUnit vs PersistenceContext
In few project I have been successfully using
@PersistenceUnit(unitName = "MiddlewareJPA")
EntityManagerFactory emf;
...
EntityManager entityManager = emf.createEntityManager();
to obtain for Database connection, but some days ago I was trying to move my project to and it couldn't create . I was googling it and I found that I should try change toEntityManager
Jboss EAP 6.2
EntityManager
@PersistenceUnit
@PersistenceContext(unitName = "MiddlewareJPA")
private EntityManager entityManager;
to obtain EntityManager. It worked but I don't know why. What is the difference bettween and ? What are pros and cons of each one? Where should we be using one of them? PersistenceUnit
PersistenceContext