HQL uses multiple column Types in a inconsitent manner between Where and Order By clauses

Description

When a type maps to multiple columns and that type is used in HQL the generated SQL will order the values in different manner in the Order By clause then it does in the Where clause. The Order By clause assumes the fields are mapped in order of importance, while the where clause assumes not field is more important then any other.

For example assume a database stores a timestamp you using multiple fields (T2SCEN T2SYER T2SMTH T2SDAY T2STIM : century year month day time) and that there is a type that turns those fields into a Calendar. Now that type is used in an entity class named WorkOrder with a field named scheduled. The following HQL query:

Select wo From WorkOrder wo WHERE wo.scheduled > :scheduled Order By wo.scheduled

Will generate the following SQL

select
...
from
SVDSPT workorder0_
where
workorder0_.T2SCEN>?
and workorder0_.T2SYER>?
and workorder0_.T2SMTH>?
and workorder0_.T2SDAY>?
and workorder0_.T2STIM>?
order by
workorder0_.T2SCEN,
workorder0_.T2SYER,
workorder0_.T2SMTH,
workorder0_.T2SDAY,
workorder0_.T2STIM

The Order By clause will order the values as one would expect for date, that is 2012-05-03T12:12:12 comes after 0001-12-01T00:00:00.
The Where clause on the other hand implies that 2012-05-03T12:12:12 does not come after 0001-12-01T00:00:00, since the month 5>12 will be false.

Environment

Java 1.7.0 Eclipse 3.7.2

Assignee

Unassigned

Reporter

Mike Dunn

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure