Skip to content

Commit 342afd2

Browse files
committed
improve/modernize some error messages
Signed-off-by: Gavin King <[email protected]>
1 parent f7adc58 commit 342afd2

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public NonUniqueObjectException(String message, Object entityId, String entityNa
4141
*/
4242
public NonUniqueObjectException(Object entityId, String entityName) {
4343
this(
44-
"A different object with the same identifier value was already associated with the session",
44+
"A different object with the same identifier value was already associated with this persistence context",
4545
entityId,
4646
entityName
4747
);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class StaleObjectStateException extends StaleStateException {
2525
* @param identifier The identifier of the entity
2626
*/
2727
public StaleObjectStateException(String entityName, Object identifier) {
28-
this( entityName, identifier,
29-
"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)" );
28+
this( entityName, identifier, "Row was already updated or deleted by another transaction" );
3029
}
3130

3231
/**

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
/**
1010
* Thrown when a version number or timestamp check failed, indicating that
1111
* the {@link Session} contained stale data (when using long transactions
12-
* with versioning). Also occurs if we try to delete or update a row that
12+
* with versioning). Also occurs on attempts to delete or update a row that
1313
* does not exist.
14-
* <p>
15-
* Note that this exception sometimes indicates that the user failed to
16-
* specify the correct {@code unsaved-value} strategy for an entity.
1714
*
1815
* @author Gavin King
1916
*/

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package org.hibernate;
88

99
/**
10-
* This exception is thrown when an invalid {@link LockMode} is selected for an entity.
10+
* Thrown when an invalid {@link LockMode} is requested for a given entity, in
11+
* particular, when a {@linkplain Session#setReadOnly(Object, boolean) read only}
12+
* entity is locked with a mode stricter than {@link LockMode#READ READ}.
1113
*
1214
* @author John O'Hara
1315
*/

hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ private ImmutableEntityEntry(
8484

8585
@Override
8686
public void setLockMode(LockMode lockMode) {
87-
switch ( lockMode ) {
88-
case NONE:
89-
case READ:
90-
setCompressedValue( LOCK_MODE, lockMode );
91-
break;
92-
default:
93-
throw new UnsupportedLockAttemptException( "Lock mode not supported" );
87+
if ( lockMode.greaterThan(LockMode.READ) ) {
88+
throw new UnsupportedLockAttemptException( "Lock mode "
89+
+ lockMode + " not supported for read-only entity" );
90+
}
91+
else {
92+
setCompressedValue( LOCK_MODE, lockMode );
9493
}
9594
}
9695

0 commit comments

Comments
 (0)