Created
August 10, 2016 17:54
-
-
Save dilnei/8b113b0b3534c71f3cae48180c3e5101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.dilneicunhaweblog.model.usefull; | |
import javax.enterprise.context.RequestScoped; | |
import javax.enterprise.inject.Disposes; | |
import javax.enterprise.inject.Produces; | |
import javax.persistence.EntityManager; | |
import javax.persistence.EntityManagerFactory; | |
import javax.persistence.Persistence; | |
/** | |
* @author Dilnei | |
* | |
* Classe responsavel por fornecer as instâncias do Entity Manager. Quando a CDI | |
* precisar criar o Objeto ela utilizará o método com | |
* @Produces | |
*/ | |
public class JPAUtil { | |
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("weblogPU"); | |
@RequestScoped | |
@Produces | |
public EntityManager getEntityManager() { | |
return emf.createEntityManager(); | |
} | |
// Recebe uma Entity Manager e faz o seu fechamento(@Disposes(ela sera descartada através desta annotation)). | |
public void close(@Disposes EntityManager em) { | |
em.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment