String query = "FROM A st, B g "
+ "WHERE st.name = g.name AND st.name LIKE :name AND "
+ "g.id = ANY (SELECT c FROM C "
+ "WHERE CASE WHEN name = 'test' THEN condiction >= :value end)";
try {
return (List) entityManager.createQuery(query)
.setParameter("name", "%" + name + "%")
.setParameter("value", value).getResultList();
} catch (SecurityException | IllegalStateException | RollbackException e) {
LOGGER.info(e.getMessage());
}
return null;
我得到了一个箴言:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: >= near line 1, column 336 ...
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:331)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
有关它的任何想法?我使用mysql数据库。我可以在休眠时使用CASE吗?相同的查询在命令行上正常工作。
感谢 干杯