When we use the @PersistenceContext annotation on an EntityManager in a JAVA EE environment, the container will create the entityManagerFactory (one for the whole session i guess) and will create a new EntityManager for each request ( by proxying it).
But using CDI without a JAVA EE container i saw something like this:
public class EntityManagerProducer {
private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("livraria");
@Produces
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
public void close(EntityManager em) {
em.close();
}
}
Using that approach with CDI, will have the same effect and performance? Thanks in advance for any help