无法使用Restrictions.sqlRestriction执行查询

时间:2015-03-10 14:24:06

标签: java sql spring hibernate postgresql

Hy我写了一个查询,我可以在Postgres中执行,工作正常,但是当我想用Restrictions.sqlRestriction(查询)执行时,它会出现语法错误。 这就是我尝试做的事情

criteria.add(Restrictions.sqlRestriction("SELECT * FROM job JOIN job_applications as j ON id=id_job WHERE id=(SELECT id_job FROM (SELECT id_job,COUNT (id_job_seeker) FROM job_applications GROUP BY id_job) AS foo WHERE COUNT = "+ dataTableFilter.sSearch[index]+")"));

并给出了这个

  

SEVERE:用于servlet [spring-mvc-dispatcher]的Servlet.service()   路径[/ XYX]的上下文引发异常[请求处理   失败;嵌套异常是   org.springframework.dao.InvalidDataAccessResourceUsageException:可以   不提取ResultSet; SQL [不适用];嵌套异常是   org.hibernate.exception.SQLGrammarException:无法解压缩   具有根本原因org.postgresql.util.PSQLException的ResultSet]:错误:   “SELECT”处或附近的语法错误位置:287 at   org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)     在   org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)     在   org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)     在   org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)     在   org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)     在   org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)at   org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)     在   org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)     在   org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)     在org.hibernate.loader.Loader.getResultSet(Loader.java:2065)at   org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)     在   org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)     在org.hibernate.loader.Loader.doQuery(Loader.java:909)at   org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)     在org.hibernate.loader.Loader.doList(Loader.java:2553)处   org.hibernate.loader.Loader.doList(Loader.java:2539)at   org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)at at   org.hibernate.loader.Loader.list(Loader.java:2364)at   org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)

我在互联网上查看但我真的不明白我该怎么做。任何建议我应该如何将我的查询转换为可执行文件?

0 个答案:

没有答案