diff --git a/src/docbkx/jpa.xml b/src/docbkx/jpa.xml
index 799e2b93a..429beb626 100644
--- a/src/docbkx/jpa.xml
+++ b/src/docbkx/jpa.xml
@@ -1260,7 +1260,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
You can now set up the infrastructure by implementing a CDI
Producer for the
- EntityManagerFactory:
+ EntityManagerFactory and
+ EntityManager:
class EntityManagerFactoryProducer {
@@ -1273,8 +1274,36 @@ public interface UserRepository extends JpaRepository<User, Long> {
public void close(@Disposes EntityManagerFactory entityManagerFactory) {
entityManagerFactory.close();
}
+
+ @Produces
+ @RequestScoped
+ public EntityManager createEntityManager(EntityManagerFactory entityManagerFactory) {
+ return entityManagerFactory.createEntityManager();
+ }
+
+ public void close(@Disposes EntityManager entityManager) {
+ entityManager.close();
+ }
}
+ The necessary setup can vary depending on the JavaEE environment
+ you run in. It might also just be enough to redeclare a
+ EntityManager as CDI bean as
+ follows:
+
+ class CdiConfig {
+
+ @Produces
+ @RequestScoped
+ @PersistenceContext
+ public EntityManager entityManager;
+}
+
+ In this example, the container has to be capable of creating JPA
+ EntityManagers itself. All the
+ configuration does is re-exporting the JPA
+ EntityManager as CDI bean.
+
The Spring Data JPA CDI extension will pick up all
EntityManagers availables as CDI beans
and create a proxy for a Spring Data repository whenever an bean of a