java 调用存储过程的Hibernate返回无效函数或过程名错误

4xrmg8kj  于 2023-02-02  发布在  Java
关注(0)|答案(1)|浏览(187)

这是我试图在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,我在其中定义了我的过程。添加了setters和getters。

@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
g6ll5ycj

g6ll5ycj1#

将您的namednative查询更改为包含{}

@NamedNativeQueries({`@NamedNativeQuery(
    name = "callBusinessUnitProcedure",`enter code here`
    query = "{CALL CSR_GET_BUSINS_UNIT_EXP(:v_start_year,:v_end_year)}",
    resultClass = Company.class`)
})

检查此https://stackoverflow.com/a/26381638/258741

相关问题