我正在mysql工作台中执行此查询,并且工作正常,但是如何在Hibernate条件构建器中获得相同的结果。希望任何人都能提供帮助。
查询是-
SELECT * FROM metokart.category order by category_name = (select category_name from metokart.category where category_name='Men' ORDER BY category_name DESC)DESC;
我尝试过的代码是-
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<CategoryBean> citeriaQuery = builder.createQuery(CategoryBean.class);
Root<CategoryBean> root = citeriaQuery.from(CategoryBean.class);
citeriaQuery.select(root).orderBy(builder.equal(root.get("category_name"),(citeriaQuery.select(root.get("category_name")).where(builder.equal(root.get("category_name"), name)).orderBy(builder.desc(root.get("category_name"))))));
Query<CategoryBean> query = session.createQuery(citeriaQuery);
但是它在第criteriaQuery.select
行中给出了错误