1

当条件满足时,我在 case 语句中连接字符串和表达式,如下所述的代码。

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = builder.createQuery(Object[].class);
Root<StudentRegistration> root = cq.from(StudentRegistration.class);
Expression<Object> str = builder.selectCase().when(builder.greaterThanOrEqualTo(root.get(StudentRegistration_.studentRegistrationGrade), 3),builder.concat("CDATA",root.get(StudentRegistration_.studentRegistrationGrade))).otherwise("-1");
cq.select(str);
em.createQuery(cq).getResultList();

因为在 case 语句中编写 concat 函数,所以我遇到了异常。我通过提供 builder.literal() 尝试了所有可能的方法,但我无法解决这个问题。两天以来,我一直在解决这个问题。请帮帮我。

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: || near line 1, column 314 [select case when generatedAlias0.studentRegistrationGrade >=3  then :param0 || generatedAlias0.studentRegistrationGrade else :param1 end from StudentRegistration as generatedAlias0]
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750)

提前致谢

4

1 回答 1

0

Have you set proper dialect for your DB?

于 2016-11-26T00:08:11.493 回答