Skip to content

Commit 4ec4e93

Browse files
committed
Document when the JPA infrastructure is ready for use
Closes gh-26153 See gh-21868
1 parent 7f0ab22 commit 4ec4e93

File tree

1 file changed

+12
-5
lines changed
  • framework-docs/modules/ROOT/pages/data-access/orm

1 file changed

+12
-5
lines changed

Diff for: framework-docs/modules/ROOT/pages/data-access/orm/jpa.adoc

+12-5
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,17 @@ The actual JPA provider bootstrapping is handed off to the specified executor an
268268
running in parallel, to the application bootstrap thread. The exposed `EntityManagerFactory`
269269
proxy can be injected into other application components and is even able to respond to
270270
`EntityManagerFactoryInfo` configuration inspection. However, once the actual JPA provider
271-
is being accessed by other components (for example, calling `createEntityManager`), those calls
272-
block until the background bootstrapping has completed. In particular, when you use
271+
is being accessed by other components (for example, calling `createEntityManager`), those
272+
calls block until the background bootstrapping has completed. In particular, when you use
273273
Spring Data JPA, make sure to set up deferred bootstrapping for its repositories as well.
274274

275+
As of 6.2, JPA initialization is enforced before context refresh completion, waiting for
276+
asynchronous bootstrapping to complete by then. This makes the availability of the fully
277+
initialized database infrastructure predictable and allows for custom post-initialization
278+
logic in `ContextRefreshedEvent` listeners etc. Putting such application-level database
279+
initialization into `@PostConstruct` methods or the like is not recommended; this is
280+
better placed in `Lifecycle.start` (if applicable) or a `ContextRefreshedEvent` listener.
281+
275282

276283
[[orm-jpa-dao]]
277284
== Implementing DAOs Based on JPA: `EntityManagerFactory` and `EntityManager`
@@ -284,9 +291,9 @@ to a newly created `EntityManager` per operation, in effect making its usage thr
284291

285292
It is possible to write code against the plain JPA without any Spring dependencies, by
286293
using an injected `EntityManagerFactory` or `EntityManager`. Spring can understand the
287-
`@PersistenceUnit` and `@PersistenceContext` annotations both at the field and the method level
288-
if a `PersistenceAnnotationBeanPostProcessor` is enabled. The following example shows a plain
289-
JPA DAO implementation that uses the `@PersistenceUnit` annotation:
294+
`@PersistenceUnit` and `@PersistenceContext` annotations both at the field and the method
295+
level if a `PersistenceAnnotationBeanPostProcessor` is enabled. The following example
296+
shows a plain JPA DAO implementation that uses the `@PersistenceUnit` annotation:
290297

291298
[tabs]
292299
======

0 commit comments

Comments
 (0)