I have duplicate in result in hibernate query, such as:
select new ValueObject(h.id, c.firstName, c.lastName)
from HistoryTable as h left join CustomerTable as c
where h.customerId = c.id and c.notDeleted
order by c.firstName, c.lastName
But, when i used DISTINCT, duplicate in result continue to appear
select distinct new ValueObject(h.id, c.firstName, c.lastName)
from HistoryTable as h left join CustomerTable as c
where h.customerId = c.id and c.notDeleted
order by c.firstName, c.lastName
But my question is, if there is any possibility to using DISTINCT for excluding duplicates for creating new ValueObject in HSQLDB query?
Hibernate does not return distinct results for a query with left or right join.
You can use Hiberante setResultTransformer
for your purposes. For more detail's explanations, why and how it resolve, look:
and