Skip to content
Browse files

Symmetric handling of readonly and writeable entity managers

  • Loading branch information...
1 parent 36fde7a commit 3ec13df06c0e329be10926026f11aaf100fddeca Adam Warski committed
Showing with 5 additions and 3 deletions.
  1. +5 −3 cdi/src/main/java/pl/softwaremill/cdiext/persistence/EntityManagerProducer.java
View
8 cdi/src/main/java/pl/softwaremill/cdiext/persistence/EntityManagerProducer.java
@@ -15,14 +15,12 @@
* @author Adam Warski (adam at warski dot org)
*/
public class EntityManagerProducer {
- @PersistenceContext
- private EntityManager entityManager;
-
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;
@Produces @RequestScoped @Writeable
public EntityManager getEntityManager() {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
return new EntityManagerTxEnlistDecorator(entityManager);
}
@@ -37,4 +35,8 @@ public EntityManager getReadOnlyEntityManager() {
public void disposeOfReadOnlyEntityManager(@Disposes @ReadOnly EntityManager readOnlyEntityManager) {
readOnlyEntityManager.close();
}
+
+ public void disposeOfWriteableEntityManager(@Disposes @Writeable EntityManager writeableEntityManager) {
+ writeableEntityManager.close();
+ }
}

0 comments on commit 3ec13df

Please sign in to comment.
Something went wrong with that request. Please try again.