[英]org.postgresql.util.PSQLException: ERROR: syntax error at or near “)”
this is the DAO method i have to retrieve the list of students from DB and on RunTime it says -这是我必须从数据库和运行时检索学生列表的 DAO 方法 -
org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
org.postgresql.util.PSQLException:错误:“)”处或附近的语法错误
which is driving me crazy.这让我发疯。 Can anyone please tell me what i might have missed?
谁能告诉我我可能错过了什么?
public List<Student> getStudentsByIds(List<Integer> studentIds) {
Session session = SessionFactoryUtils.getSession(getSessionFactory(), true);
SQLQuery query = session.createSQLQuery("SELECT * FROM students s WHERE s.id IN (:studentIds)");
query.setParameterList("studentIds", studentIds);
return query.list();
}
Probably studentIds
is an empty list and postgres does not accept empty IN clause in generated code可能
studentIds
是一个空列表,postgres 不接受生成代码中的空 IN 子句
select
...
where
students.id in (
)
Had this issue recently.最近有这个问题。 So as I got from docs psql can't handle empty lists in
IN/NOT IN (:someEmptyList)
statements cause criteriaBuilder adds empty curly braces into final sql query: (in ())
因此,当我从文档中得到时,psql 无法处理
IN/NOT IN (:someEmptyList)
语句中的空列表,导致标准生成器将空花括号添加到最终的 sql 查询中: (in ())
Imho the easiest solution will be just to check for empty list and return empty result list back.恕我直言,最简单的解决方案就是检查空列表并返回空结果列表。
Or use more advanced tools if u have complex query and u really need it => https://marcelothebuilder.github.io/java/jpa/2017/09/11/jpa-post.html或者,如果您有复杂的查询并且确实需要它, 请使用更高级的工具 => https://marcelothebuilder.github.io/java/jpa/2017/09/11/jpa-post.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.