Repository: deltaspike
Updated Branches:
  refs/heads/master 2a6058c56 -> 6950f2542


DELTASPIKE-1006 added hints about @TransactionScoped entity-managers


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6950f254
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6950f254
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6950f254

Branch: refs/heads/master
Commit: 6950f2542ae48afd535a4817d49c7796ab8db34f
Parents: 2a6058c
Author: gpetracek <[email protected]>
Authored: Sat Apr 16 10:47:54 2016 +0200
Committer: gpetracek <[email protected]>
Committed: Sat Apr 16 10:48:26 2016 +0200

----------------------------------------------------------------------
 documentation/src/main/asciidoc/data.adoc | 77 ++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6950f254/documentation/src/main/asciidoc/data.adoc
----------------------------------------------------------------------
diff --git a/documentation/src/main/asciidoc/data.adoc 
b/documentation/src/main/asciidoc/data.adoc
index 1a64188..6f7f76c 100644
--- a/documentation/src/main/asciidoc/data.adoc
+++ b/documentation/src/main/asciidoc/data.adoc
@@ -271,6 +271,83 @@ public interface PersonRepository implements Deactivatable{
 }    
 ----------------------------------------
 
+=== Support of @TransactionScoped EntityManagers
+
+For using `@TransactionScoped` beans like a 
`@TransactionScoped`-`EntityManager`,
+you need to annotate the Data-repository with @Transactional explicitly or one 
of the beans in the call-hierarchy.
+That's needed, because the context bound to `@TransactionScoped` needs to be 
active,
+before the `@TransactionScoped`-`EntityManager` gets resolved (internally).
+
+The following examples illustrate the described usages:
+
+.@TransactionScoped EntityManager combined with a simple repository
+[source,java]
+---------------------------------------------------------------------------------------
+public class EntityManagerProducer
+{
+    @Produces
+    @TransactionScoped
+    public EntityManager create() { ... }
+
+    public void close(@Disposes EntityManager em)  { ... }
+}
+
+@ApplicationScoped
+public class MyService
+{
+    @Inject
+    private MyRepository myRepository;
+
+    public void create()
+    {
+        //...
+        this.myRepository.save(...); //executed in a transaction
+        //...
+    }
+}
+
+@Transactional
+@Repository
+public interface MyRepository extends EntityRepository<MyEntity, String>
+{
+  //...
+}
+---------------------------------------------------------------------------------------
+
+.@TransactionScoped EntityManager combined with a simple repository called by 
a transactional bean
+[source,java]
+---------------------------------------------------------------------------------------
+public class EntityManagerProducer
+{
+    @Produces
+    @TransactionScoped
+    public EntityManager create() { ... }
+
+    public void close(@Disposes EntityManager em)  { ... }
+}
+
+@Transactional
+@ApplicationScoped
+public class MyService
+{
+    @Inject
+    private MyRepository myRepository;
+
+    public void create() //executed in a transaction
+    {
+        //...
+        this.myRepository.save(...);
+        //...
+    }
+}
+
+@Repository
+public interface MyRepository extends EntityRepository<MyEntity, String>
+{
+  //...
+}
+---------------------------------------------------------------------------------------
+
 === Using Multiple EntityManagers
 
 While most applications will run just fine with a single

Reply via email to