Do you know that in any case you will get excellent results without using ResultTransformer when using SetFirstResult and SetMaxResults?

When I use SetFirstResult and SetMaxResult, and if the query is combined, the result has duplicate results, not unique ones.

Then I use all types of special assistants for api criteria. But it does not filter the entire result set, it just filters the calculated result.

How can I solve this problem?

thanks

+3
source share
2 answers

I found a hacked thing to overcome this problem.

" " , . , .

// crtieria, , myCriteria = doStuffToSetupCriteria(); myCriteria.setFirstResult((-1) * itemsPerPage); myCriteria.setMaxResults(itemsPerPage);

// , myCriteria.setProjection(Projections.distinct(Projections.property( "myAllias.id" )); ids = gacc.list();

// id myCriteria.add(Restrictions.in( "myAlias.id, ));

// gacc.setProjection(); gacc.setFirstResult(0); gacc.setMaxResults(Integer.MAX_VALUE);

// = gacc.list()

, .

+4

, DB:

DetachedCriteria subQuery =...//- > , , "SetFirstResult" "SetMaxResults"

DetachedCriteria rootQuery = DetachedCriteria.For();// T -

subQuery.SetProjection(    Projections.Distinct(      Projections.ProjectionList(). (Projections.Alias ​​(Projections.Property( "ID" ), "ID" ))                       )                    );

//: , "ID" rootQuery.Add(Subqueries.PropertyIn( "ID", subQuery));

//... rootQuery T, .

, - :)

Roman

+1

Source: https://habr.com/ru/post/1703175/


All Articles