Euthymos created Bug HHH-7378
Issue Type: Bug Bug
Affects Versions: 4.1.4
Assignee: Unassigned
Components: entity-manager
Created: 09/Jun/12 9:34 AM
Description:

The following JPQL query:

SELECT s.yearMonth FROM MonthlySales s WHERE s.yearMonth <> :yearMonth ORDER BY s.yearMonth.year, s.yearMonth.month

is by Hibernate into the following SQL query:

select monthlysal0_.month as col_0_0_, monthlysal0_.year as col_0_1_ from PUBLIC.MonthlySales monthlysal0_ where monthlysal0_.month<>? and monthlysal0_.year<>? order by monthlysal0_.year, monthlysal0_.month

which is incorrect, and thus returns incorrect results. In fact, provided that yearMonth is a composite key containing two fields (year and month), Hibernate should select all the table rows that have the couple (month, year) different from the one represented by the JavaBean being passed as a parameter, which is (monthYear.year, monthYear.month).

In fact, if I run the same JPQL query on a MySQL database (thus using the MySQL dialect), the translation is the following one:

select monthlysal0_.month as col_0_0_, monthlysal0_.year as col_0_1_ from MonthlySales monthlysal0_ where (monthlysal0_.month, monthlysal0_.year)<>(?, ?) order by monthlysal0_.year, monthlysal0_.month

which is correct and consistent.

Environment: Hibernate 4.1.4, H2 database
Project: Hibernate ORM
Labels: hibernate jpa2 jpql
Priority: Major Major
Reporter: Euthymos
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira