用独特的Hibernate新关键字 [英] Hibernate new keyword with distinct

查看:112
本文介绍了用独特的Hibernate新关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 从资产中选择不同的a作为where ... 

并将其更改为

 从资产中选择新的com.org.AssetDTO(a.id,a.address,a.status)作为... 

我的问题是使用distinct关键字。它在哪里属于您正在使用新的对象查询类型的hql查询。一个想法是使用一个子选择,并在那里有独特的选择。我尝试添加 distinct a.id 但这不起作用。

解决方案

对于任何感兴趣的人来说,正确的语法是:

  select distinct com.org.AssetDTO(a.id,a .address,a.status)来自Asset作为... 


I need to take hql that is currently :

select distinct a from Asset as a where ...

and change it to

select new com.org.AssetDTO(a.id, a.address, a.status) from Asset as a where ...

My problem is with the distinct keyword. Where does it belong in an hql query where you're using the new Object query type. One thought was to use a sub-select and have my distinct there. I've tried adding distinct a.id but that doesn't work.

解决方案

Ok for anyone interested the proper syntax is

select distinct new com.org.AssetDTO(a.id, a.address, a.status) from Asset as a where ...

这篇关于用独特的Hibernate新关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆