Skip to content

Commit 7a84276

Browse files
committed
improve some info in Session javadoc
1 parent bddc144 commit 7a84276

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

hibernate-core/src/main/java/org/hibernate/ReadOnlyMode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public enum ReadOnlyMode implements FindOption {
2222
/**
2323
* Specifies that an entity should be loaded in read-only mode.
2424
* <p>
25-
* Read-only entities are not dirty-checked and snapshots of
25+
* Read-only entities are not dirty-checked, and snapshots of
2626
* persistent state are not maintained. Read-only entities can
27-
* be modified, but changes are not persisted.
27+
* be modified, but a modification to a field of a read-only
28+
* entity is not made persistent
2829
*/
2930
READ_ONLY,
3031
/**

hibernate-core/src/main/java/org/hibernate/Session.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,27 @@ public interface Session extends SharedSessionContract, EntityManager {
417417

418418
/**
419419
* Change the default for entities and proxies loaded into this session
420-
* from modifiable to read-only mode, or from modifiable to read-only mode.
420+
* from modifiable to read-only mode, or from read-only to modifiable mode.
421421
* <p>
422-
* Read-only entities are not dirty-checked and snapshots of persistent
423-
* state are not maintained. Read-only entities can be modified, but
424-
* changes are not persisted.
422+
* Read-only entities are not dirty-checked, and snapshots of persistent
423+
* state are not maintained. Read-only entities can be modified, but a
424+
* modification to a field of a read-only entity is not made persistent.
425425
* <p>
426426
* When a proxy is initialized, the loaded entity will have the same
427-
* read-only/modifiable setting as the uninitialized proxy has,
428-
* regardless of the session's current setting.
427+
* read-only/modifiable setting as the uninitialized proxy, regardless of
428+
* the {@linkplain #isDefaultReadOnly current default read-only mode}
429+
* of the session.
429430
* <p>
430431
* To change the read-only/modifiable setting for a particular entity
431-
* or proxy that already belongs to this session use
432+
* or proxy that already belongs to this session, use
432433
* {@link #setReadOnly(Object, boolean)}.
433434
* <p>
434-
* To override this session's read-only/modifiable setting for all
435-
* entities and proxies loaded by a certain {@code Query} use
435+
* To override the default read-only mode of the current session for
436+
* all entities and proxies returned by a given {@code Query}, use
436437
* {@link Query#setReadOnly(boolean)}.
438+
* <p>
439+
* Every instance of an {@linkplain org.hibernate.annotations.Immutable
440+
* immutable} entity is loaded in read-only mode.
437441
*
438442
* @see #setReadOnly(Object,boolean)
439443
* @see Query#setReadOnly(boolean)
@@ -1287,7 +1291,8 @@ public interface Session extends SharedSessionContract, EntityManager {
12871291
/**
12881292
* Set an unmodified persistent object to read-only mode, or a read-only
12891293
* object to modifiable mode. In read-only mode, no snapshot is maintained,
1290-
* the instance is never dirty checked, and changes are not persisted.
1294+
* the instance is never dirty-checked, and mutations to the fields of the
1295+
* entity are not made persistent.
12911296
* <p>
12921297
* If the entity or proxy already has the specified read-only/modifiable
12931298
* setting, then this method does nothing.
@@ -1296,17 +1301,24 @@ public interface Session extends SharedSessionContract, EntityManager {
12961301
* and proxies that are loaded into the session use
12971302
* {@link #setDefaultReadOnly(boolean)}.
12981303
* <p>
1299-
* To override this session's read-only/modifiable setting for entities
1300-
* and proxies loaded by a {@code Query} use
1301-
* {@link Query#setReadOnly(boolean)}
1304+
* To override the default read-only mode of the current session for
1305+
* all entities and proxies returned by a given {@code Query}, use
1306+
* {@link Query#setReadOnly(boolean)}.
1307+
* <p>
1308+
* Every instance of an {@linkplain org.hibernate.annotations.Immutable
1309+
* immutable} entity is loaded in read-only mode. An immutable entity may
1310+
* not be set to modifiable.
13021311
*
13031312
* @see #setDefaultReadOnly(boolean)
13041313
* @see Query#setReadOnly(boolean)
13051314
* @see IdentifierLoadAccess#withReadOnly(boolean)
1315+
* @see org.hibernate.annotations.Immutable
13061316
*
13071317
* @param entityOrProxy an entity or proxy
13081318
* @param readOnly {@code true} if the entity or proxy should be made read-only;
13091319
* {@code false} if the entity or proxy should be made modifiable
1320+
*
1321+
* @throws IllegalStateException if an immutable entity is set to modifiable
13101322
*/
13111323
void setReadOnly(Object entityOrProxy, boolean readOnly);
13121324

0 commit comments

Comments
 (0)