【问题标题】:Not all named parameters have been set: [:int]并非所有命名参数都已设置:[:int]
【发布时间】:2014-09-11 16:04:11
【问题描述】:

我使用 PostgreSQL 和休眠

我有这个功能:

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 postgresql


    【解决方案1】:

    尝试在您的 sql 查询中使用cast as int,如下所示:

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

    【讨论】:

      【解决方案2】:

      尝试在 : 之前添加双 \

      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();
      }
      

      【讨论】:

        猜你喜欢
        • 2013-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多