Vermeulen created OPENJPA-2578:
----------------------------------
Summary: criteria API "group by" creates SQL with a parameter for
a literal but does not provide it's value
Key: OPENJPA-2578
URL: https://issues.apache.org/jira/browse/OPENJPA-2578
Project: OpenJPA
Issue Type: Bug
Components: criteria
Affects Versions: 2.4.0
Reporter: Vermeulen
I have a query created using the criteria API where I group by an expression
that contains a small calculation using literal values.
OpenJPA generates the correct SQL but does not provide the value of the
generated parameter in the group by clause. The query fails with a SQL
exception similar to "The value is not set for the parameter number 9.".
I can reproduce the issue with a minimal example (see attachment) where I
create a person class with integer age and length columns and try to select the
average length grouped by the person's age / 10.
Whe running this query with trace and displaying parameters I get:
1067 testPU TRACE [main] openjpa.Query - Executing query: Query:
org.apache.openjpa.kernel.QueryImpl@be4f81; candidate class: class
entities.Person; query: null
1108 testPU TRACE [main] openjpa.jdbc.SQL - <t 5763249, conn 7326702>
executing prepstmnt 26531336 SELECT AVG(t0.length) FROM Person t0 WHERE (t0.age
> ?) GROUP BY (t0.age / ?) [params=(int) 20]
You can clearly see that the query has two parameter placeholders but only one
value is provided.
As a workaround I can call setHint("openjpa.hint.UseLiteralInSQL", "true") on
em.createQuery(query). (Which requires OpenJPA 2.4.0 when using boolean
literals, see OPENJPA-2534.)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)