-2
我想将我的sql查询转换为休眠条件。请帮助我。将sql查询转换为休眠条件
这里是我的sql查询:
select USER_ID, sum(TH_TOTAL_SCORE) as score from t_o2_user_gameplay
group by user_id order by score desc
我想将我的sql查询转换为休眠条件。请帮助我。将sql查询转换为休眠条件
这里是我的sql查询:
select USER_ID, sum(TH_TOTAL_SCORE) as score from t_o2_user_gameplay
group by user_id order by score desc
你贴什么是原生SQL查询。在您将其转换为使用Criteria API之前,我们需要先了解您的实体类及其属性。
这里有一个例子:
@Entity
public class UserGamePlay {
private Long userId;
private Long totalScore;
...
}
HQL:
SELECT ugp.userId, SUM(ugp.totalScore)
FROM UserGamePlay ugp
GROUP BY ugp.userId
ORDER BY SUM(ugp.totalScore)
标准:
List results = session.createCriteria(UserGamePlay.class)
.setProjection(Projections.projectionList()
.add(Projections.property("userId"), "userId")
.add(Projections.sum("totalScore"), "score")
.add(Projections.groupProperty("userId"), "userId")
)
.addOrder(Order.asc("score"))
.list();
谢谢很多......它适用于我... –
等都不是免费的代码写作服务...... –