Hibernate命名查询:语法错误,

时间:2016-11-10 17:55:43

标签: java postgresql hibernate

我尝试在hibernate中将Postgres函数作为命名查询运行。

我的功能签名是:

    CREATE OR REPLACE FUNCTION dummy_function(par1 integer[] DEFAULT '{}'::integer[],  par2 integer[] DEFAULT '{}'::integer[])
RETURNS TABLE(id integer, name character varying, qualified_name) AS

如您所见,参数是整数数组。

这是我的查询映射:

<sql-query name="myFn" callable="true">
        <return-scalar column="id" type="int" />
        <return-scalar column="name" type="string" />
        <return-scalar column="qualified_name" type="string" />
        { ? = call dummy_function(:par1, :par2)}  
</sql-query>

当我尝试执行查询时:

Query query = session.getNamedQuery("myFn");

query.setParameterList("par1", arrayList1.toArray());
query.setParameterList("par2", arrayList2.toArray());

query.setResultTransformer(Transformers.aliasToBean(MyCustomBean.class));
result = (List<MyCustomBean>) query.list();

我收到以下错误:&#34;语法错误附近,&#34; (完整的堆栈跟踪报告如下)。

任何人都可以帮助我吗?

谢谢, 劳拉

=====堆叠痕迹========

  

WARN [main](SqlExceptionHelper.java:144) - SQL错误:0,SQLState:   42601错误[main](SqlExceptionHelper.java:146) - 错误:语法错误   在或附近&#34;,&#34; Posizione:26错误[主要]   (NamedQueryTestCase.java:104) -   org.hibernate.exception.SQLGrammarException:无法解压缩   ResultSet org.hibernate.HibernateException:   org.hibernate.exception.SQLGrammarException:无法解压缩   ResultSet at   eu.test.dataLayer.TestDao.stackOverflowQuestion(TestDao.java:4412)at at   eu.test.test.NamedQueryTestCase.testGetHostsComponentsLevel(NamedQueryTestCase.java:98)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     在   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)     在   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)     在   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at at   org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)     在org.junit.runners.ParentRunner.run(ParentRunner.java:363)at   org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     在   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)   引起:org.hibernate.exception.SQLGrammarException:无法   提取ResultSet at   org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)     在   org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)     在   org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)     在   org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)     在   org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)     在org.hibernate.loader.Loader.getResultSet(Loader.java:2066)at   org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)     在   org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)     在org.hibernate.loader.Loader.doQuery(Loader.java:910)at   org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)     在org.hibernate.loader.Loader.doList(Loader.java:2554)at   org.hibernate.loader.Loader.doList(Loader.java:2540)at   org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)at at   org.hibernate.loader.Loader.list(Loader.java:2365)at   org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353)     在   org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1909)     在   org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)     在org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)     在eu.test.dataLayer.TestDao.stackOverflowQuestion(TestDao.java:4407)     ... 25更多引起:org.postgresql.util.PSQLException:错误:   语法错误在或附近&#34;,&#34; Posizione:26点   org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)     在   org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)     在   org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)     在org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)at   org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)     在   org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)     在   org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)     ... 39更多

0 个答案:

没有答案