[英]Hibernate Data Exception in T-SQL query (Java Web application)
我在使用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();
以下是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
通過Java運行此sql時,存在::
鑄造的“誤解”。
請用'[^0-9]*' ,'0')\\\\:\\\\:integer
替換'[^0-9]*' ,'0')::integer
'[^0-9]*' ,'0')\\\\:\\\\:integer
,它應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.