Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions documentation/src/main/asciidoc/introduction/Interacting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ entityManager.getTransaction().setRollbackOnly();

A transaction in rollback-only mode will be rolled back when it completes.

[[after-tx-rollback]]
[IMPORTANT]
====
Hibernate is not a software transactional memory.
When a transaction rolls back, Hibernate makes no attempt to roll back the state of objects held in memory to their state at the beginning of the transaction.
After a transaction rollback, the persistence context must be discarded, and the state of its entities must be assumed inconsistent with the state held by the database.
====

[[persistence-operations]]
=== Operations on the persistence context

Expand Down Expand Up @@ -294,6 +302,7 @@ Now, if an exception occurs while interacting with the database, there's no good

Therefore, a session is considered to be unusable after any of its methods throws an exception.

[[fragile-persistence-context]]
[IMPORTANT]
// .The persistence context is fragile
====
Expand Down
3 changes: 3 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
* cannot be expected to be consistent with the database after the exception occurs.
* <li>At the end of a logical transaction, the session must be explicitly {@linkplain
* #close() destroyed}, so that all JDBC resources may be released.
* <li>If a transaction is rolled back, the state of the persistence context and of its
* associated entities must be assumed inconsistent with the database, and the
* session must be discarded.
* <li>A {@code Session} is never thread-safe. It contains various different sorts of
* fragile mutable state. Each thread or transaction must obtain its own dedicated
* instance from the {@link SessionFactory}.
Expand Down
6 changes: 6 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
* {@code session.getTransaction().begin()}, and ends with a call to {@link #commit()}
* or {@link #rollback()}.
* <p>
* When a transaction rolls back, Hibernate makes no attempt to roll back the state of
* entity instances held in memory to their state at the beginning of the transaction.
* After a transaction rollback, the current {@linkplain Session persistence context}
* must be discarded, and the state of its entities must be assumed inconsistent with
* the state held by the database.
* <p>
* A single session might span multiple transactions since the notion of a session
* (a conversation between the application and the datastore) is of coarser granularity
* than the concept of a database transaction. However, there is at most one uncommitted
Expand Down