Skip to content

Commit 1d8327f

Browse files
committed
HHH-9697 - Complete documentation of new approach and APIs for SessionFactory building
1 parent 6417a46 commit 1d8327f

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

documentation/src/main/asciidoc/topical/bootstrap/JpaBootstrapping.adoc

+48-14
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,61 @@
22
:toc:
33

44
Bootstrapping Hibernate as a JPA provider can be done in a JPA-spec compliant manner or using a proprietary
5-
bootstrapping approach. The standardized approach has some limitations in certain environments, which
6-
we will get into below. But aside from those limitations, it is *highly* recommended that you use JPA-standardized
7-
boostrapping.
5+
bootstrapping approach. The standardized approach has some limitations in certain environments. But aside from
6+
those limitations, it is *highly* recommended that you use JPA-standardized boostrapping.
87

9-
NOTE: Under the covers, all of Hibernate's JPA bootstrapping makes use of its core bootstrapping. See the
10-
_Native Bootstrapping_ guide for information.
8+
NOTE: Under the covers, all of Hibernate's JPA bootstrapping makes use of its core bootstrapping. Be sure to see
9+
the _Native Bootstrapping_ guide as well.
1110

1211
== JPA-compliant bootstrapping
1312

14-
JPA actually defines 2 different ways to bootstrap a JPA provider. It uses the terms "EE" and "SE" for these 2
15-
approaches, but those terms are very misleading in this context. What the JPA spec calls EE bootstrapping is cases
16-
where a container (EE, OSGi, etc) will manage and inject the persistence context on behalf of the application. What
17-
it calls SE bootstrapping is everything else. We will use the terms managed and non-managed in this guide.
13+
In JPA we are ultimately interested in bootstrapping an `javax.persistence.EntityManagerFactory` instance. The
14+
JPA specification defines 2 primary standardized bootstrap approaches depending on how the application intends to
15+
access the `javax.persistence.EntityManager` instances from an `EntityManagerFactory`. It uses the terms "EE" and
16+
"SE" for these 2 approaches, but those terms are very misleading in this context. What the JPA spec calls EE
17+
bootstrapping is cases where a container (EE, OSGi, etc) will manage and inject the persistence context on behalf
18+
of the application. What it calls SE bootstrapping is everything else. We will use the terms
19+
container-bootstrapping and application-bootstrapping in this guide.
1820

19-
=== Managed bootstrapping
21+
NOTE: If you would like additional details on accessing and using `EntityManager` instances, sections 7.6
22+
and 7.7 of the JPA 2.1 specification cover container-managed and application-managed EntityManagers,
23+
respectively.
2024

21-
=== Non-managed bootstrapping
2225

26+
=== Container-bootstrapping
2327

24-
== Proprietary 2-phase bootstrapping
28+
The container will build an `EntityManagerFactory` for each persistent-unit defined in the deployment's
29+
`META-INF/persistence.xml` and make that available to the application for injection via the
30+
`javax.persistence.PersistenceUnit` annotation or via JNDI lookup.
31+
32+
[[container-bootstrap-injection-example]]
33+
.Injecting a EntityManagerFactory
34+
====
35+
[source, JAVA]
36+
----
37+
@PersistenceUnit
38+
EntityManagerFactory emf;
39+
----
40+
====
41+
42+
43+
=== Application-bootstrapping
2544

45+
Rather than something a container building the `EntityManagerFactory` for the application, the application
46+
can build the `EntityManagerFactory` using the `javax.persistence.Persistence` bootstrap class. The application
47+
creates an entity manager factory by calling the createEntityManagerFactory method:
48+
49+
[[application-bootstrap-example]]
50+
.Application bootstrapped EntityManagerFactory
51+
====
52+
[source, JAVA]
53+
----
54+
// Create an EMF for our CRM persistence-unit.
55+
EntityManagerFactory emf = Persistence.createEntityManagerFactory("CRM");
56+
----
57+
====
58+
59+
60+
== Proprietary 2-phase bootstrapping
2661

27-
* times when the spec defined bootstrapping is not enough (wildfly)
28-
* runtime enhancement
62+
todo: document EntityManagerFactoryBuilder...

0 commit comments

Comments
 (0)