Author: thug
Date: Thu Mar 20 17:35:40 2014
New Revision: 1579691
URL: http://svn.apache.org/r1579691
Log:
Added transaction documentation
Modified:
deltaspike/site/trunk/content/data.mdtext
Modified: deltaspike/site/trunk/content/data.mdtext
URL:
http://svn.apache.org/viewvc/deltaspike/site/trunk/content/data.mdtext?rev=1579691&r1=1579690&r2=1579691&view=diff
==============================================================================
--- deltaspike/site/trunk/content/data.mdtext (original)
+++ deltaspike/site/trunk/content/data.mdtext Thu Mar 20 17:35:40 2014
@@ -111,13 +111,13 @@ DeltaSpike data requires an `EntityManag
in Java EE 6 applications.
:::java
- public class DataSourceProducer
+ public class EntityManagerProducer
{
@PersistenceUnit
private EntityManagerFactory emf;
- @Produces
+ @Produces // you can also make this @RequestScoped
public EntityManager create()
{
return emf.createEntityManager();
@@ -138,6 +138,15 @@ This allows the `EntityManager` to be in
`@PersistenceContext` annotation. Using multiple `EntityManager` is explored
in more detail
in a following section.
+If you use a JTA DataSource with your `EntityManager`, you also have to
configure the
+`TransactionStrategy` your repositories use. Adapt your `beans.xml` for this:
+
+ <beans>
+ <alternatives>
+
<class>org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy</class>
+ </alternatives>
+ </beans>
+
You're now ready to use repositories in your application!
# Core Concepts
@@ -650,6 +659,43 @@ attribute can be overridden with the `Si
This option will not throw an exception.
+# Transactions
+
+If you call any method expression, `@Query`-annotated method or a method from
the `EntityRepository`, the
+repository will figure out if a transaction is needed or not, and if so, if
there is already one ongoing.
+The Data module uses the `TransactionStrategy` provided by the [JPA Module][1]
for this. See the JPA module
+documentation for more details.
+
+**CAUTION:**
+
+> Some containers do not support `BeanManagedUserTransactionStrategy`! As JTA
has still some portability
+> issues even in Java EE 7, it might be required that you implement your own
`TransactionStrategy`.
+> We will think about providing an acceptable solution for this.
+
+**CAUTION:**
+
+> Annotating Repository methods with `@Transactional` is not yet supported,
but will follow.
+
+If you need to open a transaction on a concrete repository method, we
currently recommend creating an extension
+(see next chapter) which uses `@Transactional` and might look like the
following sample.
+
+ :::java
+ public class TxExtension<E> implements TxRepository // this is your
extension interface
+ {
+ @Inject
+ private EntityManager em;
+
+ @Override @Transactional
+ public List<E> transactional(ListResultCallback callback)
+ {
+ return callback.execute();
+ }
+
+ }
+
+Repositories can then implement the `TxRepository` interface and call their
queries in the
+`transactional` method (where the callback implementation can be e.g. in an
anonymous class).
+
# Extensions
## Query Delegates
@@ -1124,4 +1170,7 @@ there must be a bean available of the ma
> If you expose another entity here, make sure that your persistence provider
> supports this. Also you
> should ensure that the entity is attached to a persistent context. Also, be
> aware that the CDI container
> will proxy a scoped bean, which might confuse the persistence provider when
> persisting / updating the
-> target entity.
\ No newline at end of file
+> target entity.
+
+
+ [1]: http://deltaspike.apache.org/jpa "JPA module"
\ No newline at end of file