Last active
August 29, 2015 14:22
-
-
Save marcelohd/a00611d1cf80adef3ba1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @ApplicationScoped | |
| public class EntityManagerProducer { | |
| private static EntityManagerFactory factory; | |
| private static final String namePu = "Persistence-Unit"; | |
| public EntityManagerProducer() { | |
| EntityManagerProducer.factory = Persistence.createEntityManagerFactory(namePu); | |
| } | |
| public static EntityManagerFactory getFactory() { | |
| return factory; | |
| } | |
| public static void setFactory(EntityManagerFactory factory) { | |
| EntityManagerProducer.factory = factory; | |
| } | |
| @Produces | |
| @RequestScoped | |
| public EntityManager createEntityManager(){ | |
| return EntityManagerProducer.getFactory().createEntityManager(); | |
| } | |
| public void closeEntityManager(@Disposes EntityManager emf){ | |
| emf.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment