deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1536188 - /deltaspike/site/trunk/content/jpa.mdtext
Date Sun, 27 Oct 2013 19:37:33 GMT
Author: gpetracek
Date: Sun Oct 27 19:37:33 2013
New Revision: 1536188

URL: http://svn.apache.org/r1536188
Log:
updated content

Modified:
    deltaspike/site/trunk/content/jpa.mdtext

Modified: deltaspike/site/trunk/content/jpa.mdtext
URL: http://svn.apache.org/viewvc/deltaspike/site/trunk/content/jpa.mdtext?rev=1536188&r1=1536187&r2=1536188&view=diff
==============================================================================
--- deltaspike/site/trunk/content/jpa.mdtext (original)
+++ deltaspike/site/trunk/content/jpa.mdtext Sun Oct 27 19:37:33 2013
@@ -38,7 +38,7 @@ The following example shows a simple pro
 Producing it as request scoped bean means that the dispose method will be called on finishing
the request.
 As an alternative it's possible to use a special scope called `@TransactionScoped` provided
by the same DeltaSpike module.
 
-Producer for the default EntityManager:
+Producer for the default EntityManager (no EE-Server):
 
     :::java
     //...
@@ -64,6 +64,32 @@ Producer for the default EntityManager:
         }
     }
 
+Producer for the default EntityManager (EE-Server):
+
+    :::java
+    @ApplicationScoped
+    public class EntityManagerProducer
+    {
+        @PersistenceUnit
+        private EntityManagerFactory entityManagerFactory;
+
+        @Produces
+        @Default
+        @RequestScoped
+        public EntityManager create()
+        {
+            return this.entityManagerFactory.createEntityManager();
+        }
+
+        public void dispose(@Disposes @Default EntityManager entityManager)
+        {
+            if (entityManager.isOpen())
+            {
+                entityManager.close();
+            }
+        }
+    }
+
 The following examples show how to use the `EntityManager` produced by the example above.
 
 Beans with transactional method:



Mime
View raw message