Convert string to int in Hibernate order criterion

后端 未结 2 1088
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 09:57

Basically, my question is the same as this one, but for Java\'s (JBoss) Hibernate: How can we order a column as int using hibernate criteria API?

I want to create an or

2条回答
  •  滥情空心
    2021-02-06 10:49

    Despite the topic is old and may be the problem were solved, I'll post solution. Maybe it will be helpful in future for someone.

    criteria.addOrder(new org.hibernate.criterion.Order("anystring", true) {
                @Override
                public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
                    return "cast(id as int)";
                }
            });
    

提交回复
热议问题