Skip to content

Commit 84a1f22

Browse files
committed
warnings about pc lifecycle in doc
1 parent 71a335d commit 84a1f22

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

documentation/src/main/asciidoc/introduction/Interacting.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ At any given moment, an instance may be associated with at most one persistence
5454

5555
The lifetime of a persistence context usually corresponds to the lifetime of a transaction, though it's possible to have a persistence context that spans several database-level transactions that form a single logical unit of work.
5656

57+
[WARNING]
58+
====
59+
A persistence context—that is, a `Session` or `EntityManager`—absolutely positively **must not be shared between multiple threads or between concurrent transactions.**
60+
61+
If you accidentally leak a session across threads, you will suffer.
62+
====
63+
64+
.Container-managed peristence contexts
65+
****
66+
In a container environment, the lifecycle of a persistence context scoped to the transaction will usually be managed for you.
67+
****
68+
5769
There are several reasons we like persistence contexts.
5870

5971
1. They help avoid _data aliasing_: if we modify an entity in one section of code, then other code executing within the same persistence context will see our modification.

0 commit comments

Comments
 (0)