5
votes

I work with PostgreSQL and hibernate

I have this function :

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

    }

after running my project

I have this error :

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)

when I run this query :

select max(NULLIF(split_part(num_ordre_decision, '/', 3), '')::int) from decision

in database I have the correct result

for example related to this kind of data in database :

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

I have 1001

but my problem is related to hibernate

2

2 Answers

5
votes

try using cast as int like below in your sql query:

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

Try putting double \ before :

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