并非所有命名参数都已设置:[:int]

时间:2014-09-11 16:04:11

标签: hibernate postgresql

我使用PostgreSQL和hibernate

我有这个功能:

public List getMaxNumOrder (){

        String query= "select max(NULLIF(split_part(num_ordre_decision, '/', 3), '')::int) from decision";

        SQLQuery sqlQuery = this.getSession().createSQLQuery(query);

         return sqlQuery.list();

    }
运行我的项目后

我有这个错误:

org.hibernate.QueryException: Not all named parameters have been set: [:int] [select max(NULLIF(split_part(num_ordre_decision, '/', 3), '')::int) from decision]
    at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:339)
    at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:228)

当我运行此查询时:

从决定中选择max(NULLIF(split_part(num_ordre_decision,'/',3),''):: int)

在数据库中我有正确的结果

例如与数据库中的此类数据相关:

''
''
'4/35/677'
'4/35/1001'
'4/35/99'

我有 1001

但我的问题与hibernate相关

2 个答案:

答案 0 :(得分:2)

尝试在SQL查询中使用如下所示的cast as int

String query= "select max(cast(NULLIF(split_part(num_ordre_decision, '/', 3), '') AS int)) from decision";

答案 1 :(得分:0)

尝试将双 \ 放在 : 之前

public List getMaxNumOrder (){
    String query= "select max(NULLIF(split_part(num_ordre_decision, '/', 3), '')\\:\\:int) from decision";

    SQLQuery sqlQuery = this.getSession().createSQLQuery(query);

    return sqlQuery.list();
}