The sleep mode criterion with the forecast does not return the conditions under which the criteria are met

I am using spring-hibernate and using the HibernateDAOSupport class. I have two tables mapped to each other one at a time. I fulfill the criteria below.

DetachedCriteria criteria = getCriteria( "a" ) .setProjection( Projections.projectionList() .add( Projections.groupProperty("a.id" ) ) .add( Projections.count( "a.id" ), "count" ) ) .createCriteria( "huApps", "hu") .addOrder( Order.desc( "count" ) ) ; 

this works well and create the following query

 select this_.id as y0_, count(this_.id) as y1_ from apps this_ inner join huapps huapp1_ on this_.id=huapp1_.appid group by this_.id order by y1_ desc 

As a result, it returns a list of object[] . But I want it to return List<App> (App is the class on which I implemented / created the criteria). I want him to create a request

 select this_ from apps this_ inner join huapps huapp1_ on this_.id=huapp1_.appid group by this_.id order by y1_ desc 

Please help me in writing the right criteria. I also tried with sqlProjection() , but even this did not work. Is there any way to achieve this?

+4
source share
2 answers

You are trying to add orger for new criteria, which is the result of the detachedCriteria.createCriteria("huApps", "hu") function. This function returns new criteria for the huApp property class.

Try replacing the criteria as follows:

 DetachedCriteria detachedCriteria = DetachedCriteria.forClass(A.class); detachedCriteria.setProjection(Projections.projectionList() .add(Projections.groupProperty("id")) .add(Projections.count("id"), "count") ); detachedCriteria.createCriteria("huApps", "hu"); detachedCriteria.addOrder(Order.desc("count")); List<A> list = detachedCriteria.getExecutableCriteria(getSession()).list(); 

This works well for me.

+1
source

Try to call

 DetachedCriteria criteria = getCriteria( "a" ) .setProjection( Projections.projectionList() .add( Projections.groupProperty("a.id" ), "id" ) .add( Projections.count( "a.id" ), "count" ) ) .createCriteria( "huApps", "hu") .addOrder( Order.desc( "count" ) ) .setResultTransformer(Transformers.aliasToBean(App.class)) 

This should map the properties alias to the fields of the specified bean. The application needs setters and getters in the corresponding fields

0
source

All Articles