简体   繁体   English

org.postgresql.util.PSQLException:错误:“)”处或附近的语法错误

[英]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.

相关问题 org.postgresql.util.PSQLException:错误:语法错误在“$ 1”或附近 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1” org.postgresql.util.PSQLException:错误:“ 7”或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “7” org.postgresql.util.PSQLException:错误:“-”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “-” org.postgresql.util.PSQLException:错误:“(”或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “(” org.postgresql.util.PSQLException:错误:Java 中«,» 附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error near «,» in Java 引起:org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" org.postgresql.util.PSQLException:错误:在“with”处或附近出现语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near "with" org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - org.postgresql.util.PSQLException: ERROR: syntax error at or near “:” Java 中的错误:org.postgresql.util.PSQLException:错误:语法错误附近; - Error in Java: org.postgresql.util.PSQLException: ERROR: syntax error near ; 异常:org.postgresql.util.PSQLException:错误:“调用”处或附近的语法错误 - Exception : org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM