Query with literal parameter and fails with attribute converter
Activity

Former user July 30, 2016 at 2:50 AM
Fixed in master only.

Former user July 30, 2016 at 2:49 AM
This was actually fixed in 5.2.1. I've added it to changelog.txt for 5.2.1.
Janario Oliveira March 16, 2016 at 1:32 AM
The PR works as a fallback and don't break specification
If the literal can be converted it will be and then the converted literal will be applied as expected by JPA 2.1 3.8
> getDataType().getReturnedClass().equals( converterTypeAdapter.getModelType() )
https://github.com/hibernate/hibernate-orm/pull/1284/files#diff-1638f423d5e9f6e695b0fb8ceb59a12eR93
The PR:
If the literal can not be converted by AttributeConverter and it is already a valid converted value of the same type it can be used
> getDataType().getReturnedClass().equals( converterTypeAdapter.getJdbcType() )
https://github.com/hibernate/hibernate-orm/pull/1284/files#diff-1638f423d5e9f6e695b0fb8ceb59a12eR104

Former user March 15, 2016 at 11:31 PM
With respect to enums, this duplicates HHH-10282. As with HHH-10282, this is not a bug, but an enhancement request.
I am not sure if it is safe to say, "As I see the literal parameter is the same type of the database type, so it doesn't need to be converted.". It may be OK for enums, but maybe not in general. I'm not sure if this fix is appropriate.
Also, JPA 2.1, .3.8 Type Conversion of Basic Attributes says:
"When such converted attributes are used in comparison operations with literals or parameters, the value of the literal or parameter to which they are compared must also be converted."
, WDYT?
Since this is an enhancement request, not a bug, this should not be backported to 5.0 branch.

Former user March 14, 2016 at 10:57 PM
Reopening because commit to 5.0 was reverted. I will re-apply it for 5.0.10.
When I declare a query with a literal parameter it thows an exception:
Caused by: org.hibernate.QueryException: AttributeConverter domain-model attribute type [org.hibernate.test.converter.literal.IntegerWrapper] did not match query literal type [java.lang.Integer]
at org.hibernate.hql.internal.ast.tree.LiteralNode.determineConvertedValue(LiteralNode.java:107)
at org.hibernate.hql.internal.ast.tree.LiteralNode.setExpectedType(LiteralNode.java:87)
at org.hibernate.hql.internal.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:62)
at org.hibernate.hql.internal.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1369)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4657)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2130)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2058)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:607)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
... 21 more
As I see the literal parameter is the same type of the database type, so it doesn't need to be converted