[jira] [Commented] (OPENJPA-2578) criteria API "group by" creates SQL with a parameter for a literal but does not provide it's value

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Commented] (OPENJPA-2578) criteria API "group by" creates SQL with a parameter for a literal but does not provide it's value

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/OPENJPA-2578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16115257#comment-16115257 ]

Pawel Veselov commented on OPENJPA-2578:
----------------------------------------

This also affects 2.4.2, and also 2.2.x. It's extremely annoying.

> 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
>         Attachments: openjpa_2578_test.zip
>
>
> 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.4.14#64029)
Loading...