当满足条件时,Iam在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函数iam低于异常。我通过给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)
提前致谢
答案 0 :(得分:0)
您是否为数据库设置了正确的方言?