问题
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.
回答1:
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 ...
来源:https://stackoverflow.com/questions/6984135/hibernate-new-keyword-with-distinct