[英]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: 我在使用
hibernate
sessionFactory在Java应用程序中执行以下T-SQL脚本时遇到问题,但是,当我在PostgreSQL中运行该SQL代码时,该SQL代码会起作用:
...
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: 以下是Eclipse控制台的错误:
* 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. 通过Java运行此sql时,存在
::
铸造的“误解”。
Please replace '[^0-9]*' ,'0')::integer
with '[^0-9]*' ,'0')\\\\:\\\\:integer
and it should work. 请用
'[^0-9]*' ,'0')\\\\:\\\\:integer
替换'[^0-9]*' ,'0')::integer
'[^0-9]*' ,'0')\\\\:\\\\:integer
,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.