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.
|