Piotr Przybylski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOWRkYmQzM2Y0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16671?atlOrigin=eyJpIjoiOWRkYm...
) HHH-16671 (
https://hibernate.atlassian.net/browse/HHH-16671?atlOrigin=eyJpIjoiOWRkYm...
) Unable to query key attribute that uses AttributeConverter (
https://hibernate.atlassian.net/browse/HHH-16671?atlOrigin=eyJpIjoiOWRkYm...
)
Issue Type: Bug Affects Versions: 6.2.3 Assignee: Unassigned Components: query-hql
Created: 22/May/2023 12:49 PM Priority: Major Reporter: Piotr Przybylski (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Same as
https://hibernate.atlassian.net/browse/HHH-16241 , but for entity keys, so I will
be reusing most of that issue’s contents (I didn’t test inserts, but I suppose they may be
also broken).
The model has java.time.YearMonth attributes being mapped to integers on the DB
(MariaDB):
@Convert(converter = YearMonthConverter.class)
@Column(name = "month" , nullable = false )
@Id
private YearMonth reportMonth;
Converter class:
public class YearMonthConverter implements AttributeConverter<YearMonth, Integer >
{
@Override
public Integer convertToDatabaseColumn(YearMonth attribute) {
return attribute == null ? null : (attribute.getYear() * 100) +
attribute.getMonth().getValue();
}
@Override
public YearMonth convertToEntityAttribute( Integer dbData) {
return dbData == null ? null : YearMonth.of(dbData / 100, dbData % 100);
}
}
Or use YearMonthDateType from Hypersistence Utils - the result is the same, i.e. building
a query like
entityManager.createQuery( "SELECT MAX(de.yearMonthKey) FROM DemoEntity de" );
results in an exception:
org.hibernate.QueryException: Parameter 1 of function max() has type COMPARABLE, but
argument is of type java.time.YearMonth
java.lang.IllegalArgumentException: org.hibernate.QueryException: Parameter 1 of function
max() has type COMPARABLE, but argument is of type java.time.YearMonth
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:168)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:795)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:704)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:120)
...
Caused by: org.hibernate.QueryException: Parameter 1 of function max() has type
COMPARABLE, but argument is of type java.time.YearMonth
at
app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.throwError(ArgumentTypesValidator.java:253)
at
app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.checkType(ArgumentTypesValidator.java:199)
at
app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.validate(ArgumentTypesValidator.java:98)
at
app//org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor.generateAggregateSqmExpression(AbstractSqmFunctionDescriptor.java:121)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitGenericFunction(SemanticQueryBuilder.java:4010)
at
app//org.hibernate.grammars.hql.HqlParser$GenericFunctionContext.accept(HqlParser.java:11403)
at
app//org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
at
app//org.hibernate.grammars.hql.HqlParserBaseVisitor.visitFunction(HqlParserBaseVisitor.java:1217)
at
app//org.hibernate.grammars.hql.HqlParser$FunctionContext.accept(HqlParser.java:11171)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitFunctionExpression(SemanticQueryBuilder.java:1758)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitFunctionExpression(SemanticQueryBuilder.java:253)
at
app//org.hibernate.grammars.hql.HqlParser$FunctionExpressionContext.accept(HqlParser.java:7476)
at
app//org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
at
app//org.hibernate.grammars.hql.HqlParserBaseVisitor.visitBarePrimaryExpression(HqlParserBaseVisitor.java:720)
at
app//org.hibernate.grammars.hql.HqlParser$BarePrimaryExpressionContext.accept(HqlParser.java:7064)
at
app//org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
at
app//org.hibernate.grammars.hql.HqlParserBaseVisitor.visitExpressionOrPredicate(HqlParserBaseVisitor.java:860)
at
app//org.hibernate.grammars.hql.HqlParser$ExpressionOrPredicateContext.accept(HqlParser.java:7813)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectableNode(SemanticQueryBuilder.java:1278)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelection(SemanticQueryBuilder.java:1252)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectClause(SemanticQueryBuilder.java:1235)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuery(SemanticQueryBuilder.java:1155)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:937)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:253)
at
app//org.hibernate.grammars.hql.HqlParser$QuerySpecExpressionContext.accept(HqlParser.java:1818)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:931)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:253)
at
app//org.hibernate.grammars.hql.HqlParser$SimpleQueryGroupContext.accept(HqlParser.java:1711)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectStatement(SemanticQueryBuilder.java:418)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.visitStatement(SemanticQueryBuilder.java:377)
at
app//org.hibernate.query.hql.internal.SemanticQueryBuilder.buildSemanticModel(SemanticQueryBuilder.java:295)
at
app//org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:81)
at
app//org.hibernate.internal.AbstractSharedSessionContract.lambda$interpretHql$2(AbstractSharedSessionContract.java:744)
at
app//org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:141)
at
app//org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:128)
at
app//org.hibernate.internal.AbstractSharedSessionContract.interpretHql(AbstractSharedSessionContract.java:741)
at
app//org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:786)
... 100 more
(
https://hibernate.atlassian.net/browse/HHH-16671#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16671#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:bbd69a1 )