gpt4 book ai didi

java - 将 HQL 转换为条件

转载 作者:行者123 更新时间:2023-12-01 13:15:12 25 4
gpt4 key购买 nike

我想在标准中转换 HQL。

HQL

select com from News as news " +
"join news.comments as com " +
"where news.id = :id " +
"order by com.addDate desc"

标准

    DetachedCriteria criteria = DetachedCriteria.forClass(News.class);
criteria.add(Restrictions.idEq(id));
DetachedCriteria cComment = criteria.createCriteria("comments");
cComment.addOrder(Order.desc("addDate"));
List<Comment> list = (List<Comment>)findByCriteria(cComment, false);

标准有效,但返回新闻列表。我想回复评论。请帮助我?

最佳答案

试试这个可能对你有帮助:

DetachedCriteria criteria = DetachedCriteria.forClass(News.class);
criteria.setProjection( Projections.property("com"), "com"));
criteria.add(Restrictions.idEq(id));
DetachedCriteria cComment = criteria.createCriteria("comments");
cComment.addOrder(Order.desc("addDate"));
List<String> list = (List<String>)findByCriteria(cComment, false);

关于java - 将 HQL 转换为条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com