Hibernate嵌套选择

时间:2013-01-31 09:34:11

标签: java sql hibernate jpa-2.0

我希望从以下查询中仅选择myEntity(e)结果

String query = "select e, to_char(message_date, 'yyyyMMdd') as dateOnly from myEntity e where e.lang = 'DE' and e.message.messageDate > sysdate-5 order by dateOnly desc, e.message.messageType asc"

所以当我使用以下代码时

entityManager.createQuery(query).getResultList();

将结果设为List<myEntity>,表示执行以下查询

select e from (select e, to_char(message_date, 'yyyyMMdd') as dateOnly from myEntity e where e.lang = 'DE' and e.message.messageDate > sysdate-5 order by dateOnly desc, e.message.messageType asc)

1 个答案:

答案 0 :(得分:0)

使用以下查询解决了我的问题

String query = "select e from myEntity e where e.lang = 'DE' and e.message.messageDate >     sysdate-5 order by to_char(message_date, 'yyyyMMdd') desc, e.message.messageType asc"