Unexpected warning when using the SQL TRIM function with less than 4 parameters

Description

The ANSI SQL TRIM function is defined as:

However, the first three arguments to the function are optional. Therefore, all the following calls to this function are valid:

However, any time this function is called from HQL with less than the maximum allowed of 4 parameters, the following warning message is seen in the logs, generated from the class org.hibernate.dialect.function.TemplateRenderer:

For example, the following Spring Data JPA repository method (which generates an HQL query) leads to this error:

This warning message has no impact on the actual execution of the code, which works as expected. However, WARN log level seems excessive for this case. The following portion of the code generates the warning:

At the very least, the severity level for this message should be changed to INFO. A proper check should know the minimum and maximum number of mandatory arguments allowed for the SQL function and compare the supplied number of arguments with this range. If the number of arguments is outside this range, the method must halt the operation by throwing an exception, instead of just logging a message and continuing.

Have attached a Maven project as a sample. Just run the test cases to see the aforementioned warning message being displayed.

Attachments

1

Activity

Show:

Marcel Ring June 2, 2022 at 5:52 AM

We’re using 5.4.33 and this warning is still present. The fact that the last comment was from 2017 doesn’t give much hope for a solution coming soon. Is this somewhat planned or how could we proceed on this issue.

Chris Cranford April 12, 2017 at 1:21 PM

, I understand and I agree with changing the logging level and adding the function to the message. What I am not sure about is the suggestion for throwing an exception when the supplied number of arguments are outside of [min,max]. Perhaps the reason why we didn't previously is we couldn't support a range-based argument check properly, hence why we merely logged the warning. I'm just suggesting we consider all use cases before adding the exception-case.

Steve Ebersole April 12, 2017 at 12:57 PM

The concern with "the database will do this for us" is that we often map certain "HQL functions" to differently named SQL functions - might be confusing.

Chris Cranford April 12, 2017 at 12:51 PM

I concur with Andrea, marking it with a more appropriate logging level should be sufficient. Regarding the exception piece which Andrea mentioned, I suspect the database will do this for us should it determine the provided number of arguments are incorrect resulting in a SQLException anyway.

Andrea Boriero April 12, 2017 at 10:37 AM

I think marking as DEBUG (or even INFO) is fine, for sure we have to add the function name to the log message.

As a major change may be we can add the min number of arguments the function requires, if the passed arguments are less than the min we can throw an exception.

Details

Assignee

Reporter

Labels

Components

Priority

Created June 3, 2015 at 10:45 AM
Updated June 2, 2022 at 5:52 AM