@@ -311,8 +311,8 @@ The above definition of the `dataSource` bean uses the `<jndi-lookup/>` tag from
311
311
====
312
312
313
313
You can also use Hibernate local transactions easily, as shown in the following
314
- examples. In this case, you need to define a Hibernate `LocalSessionFactoryBean`, which
315
- your application code will use to obtain Hibernate `Session` instances.
314
+ examples. In this case, you need to define a Hibernate `LocalSessionFactoryBean`,
315
+ which your application code will use to obtain Hibernate `Session` instances.
316
316
317
317
The `DataSource` bean definition will be similar to the local JDBC example shown
318
318
previously and thus is not shown in the following example.
@@ -5116,8 +5116,8 @@ chapter will then cover the other ORM technologies, showing briefer examples the
5116
5116
====
5117
5117
As of Spring Framework 5.0, Spring requires Hibernate ORM 4.3 or later for JPA support
5118
5118
and even Hibernate ORM 5.0+ for programming against the native Hibernate Session API.
5119
- Note that the Hibernate team does not maintain any versions prior to 5.0 anymore and
5120
- is likely to focus on 5.2 + exclusively soon.
5119
+ Note that the Hibernate team does not maintain any versions prior to 5.1 anymore and
5120
+ is likely to focus on 5.3 + exclusively soon.
5121
5121
====
5122
5122
5123
5123
@@ -5175,8 +5175,25 @@ configuration:
5175
5175
----
5176
5176
5177
5177
You can also access a JNDI-located `SessionFactory`, using Spring's
5178
- `JndiObjectFactoryBean` / `<jee:jndi-lookup>` to retrieve and expose it. However, that
5179
- is typically not common outside of an EJB context.
5178
+ `JndiObjectFactoryBean` / `<jee:jndi-lookup>` to retrieve and expose it.
5179
+ However, that is typically not common outside of an EJB context.
5180
+
5181
+ [NOTE]
5182
+ ====
5183
+ Spring also provides a `LocalSessionFactoryBuilder` variant, seamlessly integrating
5184
+ with `@Bean` style configuration and programmatic setup (no `FactoryBean` involved).
5185
+
5186
+ Both `LocalSessionFactoryBean` and `LocalSessionFactoryBuilder` support background
5187
+ bootstrapping, with Hibernate initialization running in parallel to the application
5188
+ bootstrap thread on a given bootstrap executor (e.g. a `SimpleAsyncTaskExecutor`).
5189
+ On `LocalSessionFactoryBean`, this is available through the "bootstrapExecutor"
5190
+ property; on the programmatic `LocalSessionFactoryBuilder`, there is an overloaded
5191
+ `buildSessionFactory` method which takes a bootstrap executor argument.
5192
+
5193
+ As of Spring Framework 5.1, such a native Hibernate setup can also expose a JPA
5194
+ `EntityManagerFactory` for standard JPA interaction next to native Hibernate access.
5195
+ See <<orm-jpa-hibernate,Native Hibernate setup for JPA>> for details.
5196
+ ====
5180
5197
5181
5198
5182
5199
[[orm-hibernate-straight]]
@@ -5781,7 +5798,7 @@ This is important especially when the hosting applications rely on different JPA
5781
5798
implementations because the JPA transformers are applied only at class loader level and
5782
5799
thus are isolated from each other.
5783
5800
5784
- [[orm-jpa-multiple]]
5801
+ [[orm-jpa-setup- multiple]]
5785
5802
===== Dealing with multiple persistence units
5786
5803
5787
5804
For applications that rely on multiple persistence units locations, stored in various
@@ -5825,6 +5842,30 @@ affect __all__ hosted units, or programmatically, through the
5825
5842
`PersistenceUnitManager` is specified, one is created and used internally by
5826
5843
`LocalContainerEntityManagerFactoryBean`.
5827
5844
5845
+ [[orm-jpa-setup-background]]
5846
+ ===== Background bootstrapping
5847
+
5848
+ `LocalContainerEntityManagerFactoryBean` supports background bootstrapping through
5849
+ the `bootstrapExecutor` property:
5850
+
5851
+ [source,xml,indent=0]
5852
+ [subs="verbatim,quotes"]
5853
+ ----
5854
+ <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
5855
+ <property name="bootstrapExecutor">
5856
+ <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
5857
+ </property>
5858
+ </bean>
5859
+ ----
5860
+
5861
+ The actual JPA provider bootstrapping will be handed off to the specified executor then,
5862
+ running in parallel to the application bootstrap thread. The exposed `EntityManagerFactory`
5863
+ proxy can be injected into other application components and is even able to respond
5864
+ `EntityManagerFactoryInfo` configuration inspection. However, once the actual JPA provider
5865
+ is being accessed by other components, e.g. calling `createEntityManager`, those calls
5866
+ will block until the background bootstrapping has completed. In particular, when using
5867
+ Spring Data JPA, make sure to set up deferred bootstrapping for its repositories as well.
5868
+
5828
5869
5829
5870
[[orm-jpa-dao]]
5830
5871
==== Implementing DAOs based on JPA: EntityManagerFactory and EntityManager
@@ -6087,6 +6128,17 @@ as well as stronger optimizations for read-only transactions. Last but not least
6087
6128
native Hibernate setup can also be expressed through `LocalSessionFactoryBuilder`,
6088
6129
seamlessly integrating with `@Bean` style configuration (no `FactoryBean` involved).
6089
6130
6131
+ [NOTE]
6132
+ ====
6133
+ `LocalSessionFactoryBean` and `LocalSessionFactoryBuilder` support background
6134
+ bootstrapping, just like the JPA `LocalContainerEntityManagerFactoryBean`.
6135
+ See <<orm-jpa-setup-background,Background bootstrapping>> for an introduction.
6136
+
6137
+ On `LocalSessionFactoryBean`, this is available through the "bootstrapExecutor"
6138
+ property; on the programmatic `LocalSessionFactoryBuilder`, there is an overloaded
6139
+ `buildSessionFactory` method which takes a bootstrap executor argument.
6140
+ ====
6141
+
6090
6142
6091
6143
6092
6144
0 commit comments