views:

34

answers:

0

Hello, I've searched on the internet but I didn't understand very much the problem:

I'm trying to build a distinct query using criteria and a distinct clause using a projection, trying to resole the lazy attribute of the projection in the distinct.

So the query will be like this

Code:

createCriteria(Parent.class) .setProject(Projections.distinct(Projections.properties("relation"))) .createCriteria("relation")

Unfortunately, the relation fields aren't fetched, this query return just a list of id's and I have to generate O(n) queries for fetching the results.

The equivalent in HQL would be

Code:

select distinct r from Parent as p join p.relation as r

Is it possible to do it using criteria?

I've seen that someone suggest to use the trasnformer, but I would like to use the distinct in the database.

Thank you very much.

Possible duplicate for NHibernate?