Hibernate调用存储过程不返回有效的函数或过程名称错误

时间:2016-08-31 15:26:30

标签: java hibernate

这是我试图在Hibernate中调用的程序。

PROCEDURE CSR_GET_BUSINS_UNIT_EXP(
                      v_start_year VARCHAR2,
                      v_end_year VARCHAR2,
                      c_bus_total OUT cursor_output,
                      c_bus_month_total OUT cursor_output,
                      c_bus_unit_info OUT cursor_output,
                      c_bus_exp_info OUT cursor_output
                      ) AS
  BEGIN
        OPEN c_bus_total FOR
            SELECT NVL(SUM(amount),0)
            FROM TIPS_BUS_UNIT
            WHERE ACCT_PER <= TO_DATE(v_start_year,'dd-mon-yyyy')
            AND ACCT_PER >= TO_DATE(v_end_year,'dd-mon-yyyy');
        OPEN c_bus_month_total FOR
           SELECT TO_CHAR(acct_per,'MON-YYYY'), NVL(SUM(amount),0)
              FROM TIPS_BUS_UNIT
              WHERE ACCT_PER <= TO_DATE(v_start_year,'dd-mon-yyyy')
              AND ACCT_PER >= TO_DATE(v_end_year,'dd-mon-yyyy')
              GROUP BY acct_per
              ORDER BY acct_per DESC;
       OPEN c_bus_unit_info FOR
           SELECT TIPS_BUNIT, NVL(SUM(amount),0)
              FROM TIPS_BUS_UNIT
              WHERE ACCT_PER <= TO_DATE(v_start_year,'dd-mon-yyyy')
              AND ACCT_PER >= TO_DATE(v_end_year,'dd-mon-yyyy')
              GROUP BY TIPS_BUNIT
              ORDER BY TIPS_BUNIT DESC;
       OPEN c_bus_exp_info FOR
              SELECT TIPS_BUNIT, TO_CHAR(acct_per,'MON-YYYY'), amount
           FROM TIPS_BUS_UNIT
           WHERE ACCT_PER <= TO_DATE(v_start_year,'dd-mon-yyyy')
           AND ACCT_PER >= TO_DATE(v_end_year,'dd-mon-yyyy')
           ORDER BY TIPS_BUNIT DESC, ACCT_PER DESC;
   END;

下面是我的POJO,我在其中定义了我的程序。添加了getter和getter。

@NamedNativeQueries({`@NamedNativeQuery(
        name = "callBusinessUnitProcedure",`enter code here`
        query = "CALL CSR_GET_BUSINS_UNIT_EXP(:v_start_year,:v_end_year)",
        resultClass = Company.class`)
    })
    @Entity
    @Table(name="TIPS_BUS_UNIT",schema ="CSR")
    public class Company implements Serializable{
    @Column(name = "TIPS_BUNIT")
        @Id
        @JsonProperty(value="businessUnit")
        private String businessUnit;

        @Column(name = "BUS_UNIT_DESC")
        @JsonProperty(value="description")
        private String description;

        @Column(name = "ACCT_PER")
        @JsonProperty(value="date")
        private String date;

        @Column(name = "AMOUNT")
        @JsonProperty(value="amount")
        private String amount;

以下是我的IMPL类,我在调用存储过程来访问数据库。

 @SuppressWarnings("unchecked")
        @Override
        public  List<Company> getWebReports()
        {

            List<Company> webReport = new ArrayList<Company>();


            webReport =  entityManager
                    .createNamedQuery("callBusinessUnitProcedure").setParameter("v_start_year","07-OCT-2007")
                    .setParameter("v_end_year", "06-JAN-2006").getResultList();
             return webReport;

当我运行这个时,我在控制台中收到以下错误。 如果其他人遇到这种问题,请帮忙......

2016-08-30 21:59:13.516  INFO 11884 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 56 ms
Hibernate: CALL CSR_GET_BUSINS_UNIT_EXP(?,?)
2016-08-30 21:59:15.199  WARN 11884 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 6576, SQLState: 65000
2016-08-30 21:59:15.199 ERROR 11884 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ORA-06576: not a valid function or procedure name

2016-08-30 21:59:15.269 ERROR 11884 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[`dispatcherServlet`]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract Result Set; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract Result Set] with root cause

java.sql.SQLException: ORA-06576: not a valid function or procedure name

1 个答案:

答案 0 :(得分:0)

更改您的namednative查询以使其上显示{}

@NamedNativeQueries({@NamedNativeQuery( name = "callBusinessUnitProcedure",在此输入代码 query = "{CALL CSR_GET_BUSINS_UNIT_EXP(:v_start_year,:v_end_year)}", resultClass = Company.class)     })

选中此https://stackoverflow.com/a/26381638/258741