The following mapping fails in using PostgreSQL 10:
@Formula("date(createdAt + interval '1 months')")
private LocalDate calculateDate;
The problem is the generated query appends root table alias before reserved word interval:
date(mytable0_.createdAt + mytable0_.interval '1 months') as formula0_0_
from mytable mytable0_
And it should be mapped as:
date(mytable0_.createdAt + interval '1 months') as formula0_0_
from mytable mytable0_
After digging in the code, it seems the problem is at org.hibernate.sql.Template class:
private static boolean isFunctionOrKeyword(
String lcToken,
String nextToken,
Dialect dialect,
SQLFunctionRegistry functionRegistry) {
return "(".equals( nextToken ) ||
KEYWORDS.contains( lcToken ) ||
isType( lcToken, dialect ) ||
isFunction( lcToken, nextToken, functionRegistry ) ||
dialect.getKeywords().contains( lcToken ) ||
FUNCTION_KEYWORDS.contains( lcToken );
}
dialect.getKeywords() only returns partition and it's deprecated.
/**
* @deprecated These are only ever used (if at all) from the code that handles identifier quoting. So
* see {@link #buildIdentifierHelper} instead
*/
@Deprecated
public Set<String> getKeywords() {
return sqlKeywords;
}
I suppose should call IdentifierHelper to check keywords in isFunctionOrKeyword method. |