简体   繁体   中英

Hibernate Data Exception in T-SQL query (Java Web application)

I have problem with executing the following T-SQL script in Java application using hibernate sessionFactory, however, this SQL code works when I run it in PostgreSQL:

...
query = session.createSQLQuery(
        "; CREATE TEMP TABLE deathuntil1 AS "+
        "     SELECT id, jamoatorgunit, organisationunitid "+
        "       , REGEXP_REPLACE( "+
        "               COALESCE( "+
        "                   substring( "+
        "                       CAST(age(deathdate,birthdate) AS character varying ) "+ 
        "                       from 1 for "+
        "                           CASE WHEN (position('years' in CAST(age(deathdate,birthdate) AS character varying ))-1)>0 THEN position('years' in CAST(age(deathdate,birthdate) AS character varying ))-1 ELSE 0 END "+
        "                       ) "+
        "               , '0'), '[^0-9]*' ,'0')::integer AS years "+
        "     FROM public.cro_death "+ 
        "     WHERE "+ 
        "       length(firstname)>= 3 "+ 

        ";" 
    );

query.executeUpdate();

the following is the error from Eclipse console:

* ERROR 2016-08-16 11:36:18,753 No value specified for parameter 1. (SqlExceptionHelper.java [qtp1843774775-20])
* ERROR 2016-08-16 11:36:18,760 Error while executing action (ExceptionInterceptor.java [qtp1843774775-20])
org.hibernate.exception.DataException: could not execute statement
at     org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135)
at     org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at     org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)


Caused by: org.postgresql.util.PSQLException: No value specified for parameter 1.
at     org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:225)
at     org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:133)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186)
... 124 more

When running this sql through java, there is a "misunderstanding" of :: casting.

Please replace '[^0-9]*' ,'0')::integer with '[^0-9]*' ,'0')\\\\:\\\\:integer and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM