I encounter this exception, if a querry is logged which contains a % symbel for a LIKE querry.
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.Integer eu.rentall.application.repository.AgpInternalOrderRepository.resetInternalOrderFromProcessing(java.lang.Long)
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:100)
Caused by: java.util.UnknownFormatConversionException: Conversion = '''
at java.base/java.util.Formatter.parse(Formatter.java:2750)
at java.base/java.util.Formatter.format(Formatter.java:2671)
at java.base/java.util.Formatter.format(Formatter.java:2625)
at java.base/java.lang.String.format(String.java:4143)
at org.jboss.logging.Slf4jLocationAwareLogger.doLogf(Slf4jLocationAwareLogger.java:81)
at org.jboss.logging.Logger.logf(Logger.java:2445)
at org.jboss.logging.DelegatingBasicLogger.debugf(DelegatingBasicLogger.java:344)
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:75)
at org.hibernate.internal.AbstractSharedSessionContract.lambda$interpretHql$2(AbstractSharedSessionContract.java:744)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:141)
I upgraded to Spring Boot 3.1.0 and now also upgraded Hibernate to 6.2.5.Final.
I also use org.slf4j:2.0.7 with org.jboss.logging:3.5.0Final as its implementation.
The log framework is ch.qos.logback:1.4.7.
For querry-logging org.hibernate.query.hql.internal.StandardHqlTranslator#translate is being called.
@Override
public <R> SqmStatement<R> translate(String query, Class<R> expectedResultType) {
HqlLogging.QUERY_LOGGER.debugf( "HQL : " + query );
...
}
After debugging through all this code I found the problem is the use of HqlLogging.QUERY_LOGGER.debugf instead of HqlLogging.QUERY_LOGGER.debug.
The difference between those two meathos is this line in org.jboss.logging.Slf4jLocationAwareLogger:
// doLog(..)
final String text = parameters == null || parameters.length == 0 ? String.valueOf(message) : MessageFormat.format(String.valueOf(message), parameters);
// doLogf(..)
final String text = parameters == null ? String.format(format) : String.format(format, parameters);
Since StandardHqlTranslator does not provide parameters, parameters is set to the empty array.
therefore String.format(format, parameters) is called which considers % a format expression.
Solution:
org.hibernate.query.hql.internal.StandardHqlTranslator#translate should bechanged to call:
HqlLogging.QUERY_LOGGER.debug( "HQL : " + query );