Hibernate- Sql查询转换对象

时间:2015-08-03 17:09:52

标签: java mysql spring hibernate

我有Spring MVC应用程序和hibernate一起使用。我可以将hql查询转换为对象,但同样不适用于SQL。我有以下查询要转换为Jpassatempos对象:

List<Jpassatempos> list = (List<Jpassatempos>) 
session.createSQLQuery("select jpassatempos.* from jpassatempos 
left join jcodigos on jpassatempos.Id = jcodigos.PassatemposId 
where jpassatempos.Id in 
     (select jpassatempos_concorrentes.PassatemposId from jpassatempos_concorrentes  
       left join jpassatempos on jpassatempos_concorrentes.PassatemposId = jpassatempos.Id 
       where  jpassatempos_concorrentes.ConcorrentesId = ? and jpassatempos.DataFim > current_date group by jpassatempos_concorrentes.PassatemposId) 
or jpassatempos.Id in 
     (select  jmeuspassatempos.PassatemposId from jmeuspassatempos 
       where ConcorrentesId = ? group by jmeuspassatempos.PassatemposId) 
group by jpassatempos.Id order by sum(jcodigos.NumBolhasRestantes)").setParameter(0, id).setParameter(1, id).list();

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

使用setResultTransformer(Transformers.aliasToBean(Jpassatempos.class))