My Class:
Code:
public class Concurso {
private Long id;
private String nome;
private Date ultimaModificacao;
// getter & setters
}
My mapping:
Code:
<class name="Concurso" table="xyz">
<id name="id" unsaved-value="null" type="long">
<column name="ID"/>
</id>
<property name="nome"/>
<property name="ultimaModificacao" type="MyDateTimeType">
<column name="DT_ALTERACAO" not-null="true" sql-type="DATE"/>
<column name="HR_ALTERACAO" not-null="true" sql-type="TIME"/>
</property>
<query name="find">
from
Concurso concurso
order by
concurso.ultimaModificacao desc
</query>-->
</class>
My custom type 'MyDateTimeType' joins the 2 columns and builds (in the nullSafeGet method) a java.util.Date object to be configured in the 'Concurso' instances.
When I load the named query 'find' and execute the query.list(), the generated sql query is something like:
Code:
select
c.ID, c.DT_ALTERACAO, c.HR_ALTERACAO
from
xyz c
order by c.DT_ALTERACAO, c.HR_ALTERACAO desc
The problem is in the 'order' clause. Only the second column receives the 'desc' word. The correct should be:
Code:
select
c.ID, c.DT_ALTERACAO, c.HR_ALTERACAO
from
xyz c
order by c.DT_ALTERACAO DESC, c.HR_ALTERACAO DESC
What can I do to solve this?