Skip to content

Commit c319d37

Browse files
committed
replace logging with meaningful exception
1 parent 6d53c94 commit c319d37

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

hibernate-core/src/main/java/org/hibernate/jpa/internal/util/LockModeTypeHelper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ public static LockMode interpretLockMode(Object value) {
3030
if ( value == null ) {
3131
return LockMode.NONE;
3232
}
33-
if (value instanceof LockMode) {
34-
return (LockMode) value;
33+
else if ( value instanceof LockMode lockMode ) {
34+
return lockMode;
3535
}
36-
else if (value instanceof LockModeType) {
37-
return getLockMode( (LockModeType) value );
36+
else if ( value instanceof LockModeType lockModeType ) {
37+
return getLockMode( lockModeType );
3838
}
39-
else if (value instanceof String) {
40-
return LockMode.fromExternalForm( (String) value );
39+
else if ( value instanceof String string ) {
40+
return LockMode.fromExternalForm( string );
41+
}
42+
else {
43+
throw new IllegalArgumentException( "Could not interpret '" + value.getClass().getName() + "' as a LockMode" );
4144
}
42-
43-
throw new IllegalArgumentException( "Unknown lock mode source: '" + value + "'; can't convert from value of type " + value.getClass() );
4445
}
4546

4647
}

hibernate-core/src/main/java/org/hibernate/query/QueryLogging.java

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ static <T> T subLogger(String subName, Class<T> loggerJavaType) {
5454
@Message(value = "Error in named query: %s", id = 90003001)
5555
void namedQueryError(String queryName, @Cause HibernateException e);
5656

57-
@LogMessage(level = INFO)
58-
@Message(value = "Unable to determine lock mode value: %s -> %s", id = 90003002)
59-
void unableToDetermineLockModeValue(String hintName, Object value);
60-
6157
@LogMessage(level = INFO)
6258
@Message(value = "Ignoring unrecognized query hint [%s]", id = 90003003)
6359
void ignoringUnrecognizedQueryHint(String hintName);

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractCommonQueryContract.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public final boolean applyHint(String hintName, Object value) {
286286
}
287287

288288
protected void applySynchronizeSpacesHint(Object value) {
289-
QueryLogging.QUERY_LOGGER.debug( "Query spaces hint was specified for non-native query; ignoring" );
289+
throw new IllegalArgumentException( "Query spaces hint was specified for non-native query" );
290290
}
291291

292292
protected final boolean applySelectionHint(String hintName, Object value) {
@@ -452,13 +452,13 @@ protected final void applyLockModeHint(Object value) {
452452
else if ( value instanceof LockModeType lockModeType ) {
453453
applyLockModeType( lockModeType );
454454
}
455-
else if ( value instanceof String ) {
456-
applyHibernateLockMode( interpretLockMode( value ) );
455+
else if ( value instanceof String string ) {
456+
applyHibernateLockMode( LockMode.fromExternalForm( string ) );
457457
}
458458
else {
459459
throw new IllegalArgumentException(
460460
String.format(
461-
"Native lock-mode hint [%s] must specify %s or %s. Encountered type : %s",
461+
"Native lock-mode hint [%s] must specify %s or %s. Encountered type: %s",
462462
HINT_NATIVE_LOCKMODE,
463463
LockMode.class.getName(),
464464
LockModeType.class.getName(),
@@ -469,15 +469,8 @@ else if ( value instanceof String ) {
469469
}
470470

471471
protected void applyAliasSpecificLockModeHint(String hintName, Object value) {
472-
// extract the alias
473472
final String alias = hintName.substring( HINT_NATIVE_LOCKMODE.length() + 1 );
474-
// determine the LockMode
475-
try {
476-
getLockOptions().setAliasSpecificLockMode( alias, interpretLockMode( value ) );
477-
}
478-
catch ( Exception e ) {
479-
QueryLogging.QUERY_MESSAGE_LOGGER.unableToDetermineLockModeValue( hintName, value );
480-
}
473+
getLockOptions().setAliasSpecificLockMode( alias, interpretLockMode( value ) );
481474
}
482475

483476
protected void applyFollowOnLockingHint(Boolean followOnLocking) {
@@ -700,8 +693,6 @@ public boolean isBound(Parameter<?> param) {
700693
}
701694

702695
public <T> T getParameterValue(Parameter<T> param) {
703-
QueryLogging.QUERY_LOGGER.tracef( "#getParameterValue(%s)", param );
704-
705696
checkOpenNoRollback();
706697

707698
final QueryParameterImplementor<T> parameter = getParameterMetadata().resolve( param );

0 commit comments

Comments
 (0)