improve/modernize some error messages

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-09-02 09:05:13 +02:00
parent f7adc587b2
commit 342afd28d4
5 changed files with 12 additions and 15 deletions

View File

@ -41,7 +41,7 @@ public class NonUniqueObjectException extends HibernateException {
*/
public NonUniqueObjectException(Object entityId, String entityName) {
this(
"A different object with the same identifier value was already associated with the session",
"A different object with the same identifier value was already associated with this persistence context",
entityId,
entityName
);

View File

@ -25,8 +25,7 @@ public class StaleObjectStateException extends StaleStateException {
* @param identifier The identifier of the entity
*/
public StaleObjectStateException(String entityName, Object identifier) {
this( entityName, identifier,
"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)" );
this( entityName, identifier, "Row was already updated or deleted by another transaction" );
}
/**

View File

@ -9,11 +9,8 @@ package org.hibernate;
/**
* Thrown when a version number or timestamp check failed, indicating that
* the {@link Session} contained stale data (when using long transactions
* with versioning). Also occurs if we try to delete or update a row that
* with versioning). Also occurs on attempts to delete or update a row that
* does not exist.
* <p>
* Note that this exception sometimes indicates that the user failed to
* specify the correct {@code unsaved-value} strategy for an entity.
*
* @author Gavin King
*/

View File

@ -7,7 +7,9 @@
package org.hibernate;
/**
* This exception is thrown when an invalid {@link LockMode} is selected for an entity.
* Thrown when an invalid {@link LockMode} is requested for a given entity, in
* particular, when a {@linkplain Session#setReadOnly(Object, boolean) read only}
* entity is locked with a mode stricter than {@link LockMode#READ READ}.
*
* @author John O'Hara
*/

View File

@ -84,13 +84,12 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry {
@Override
public void setLockMode(LockMode lockMode) {
switch ( lockMode ) {
case NONE:
case READ:
setCompressedValue( LOCK_MODE, lockMode );
break;
default:
throw new UnsupportedLockAttemptException( "Lock mode not supported" );
if ( lockMode.greaterThan(LockMode.READ) ) {
throw new UnsupportedLockAttemptException( "Lock mode "
+ lockMode + " not supported for read-only entity" );
}
else {
setCompressedValue( LOCK_MODE, lockMode );
}
}