gpt4 book ai didi

java.lang.IllegalAccessException : When calling stored procedure from Hibhernate

转载 作者:行者123 更新时间:2023-12-01 12:00:31 25 4
gpt4 key购买 nike

我无法使用注释从 hibernate 状态调用 SP。每次我调用 SP hibernate 时都会显示错误为

java.lang.IllegalAccessException: Class org.hibernate.dialect.Oracle9Dialect can not access a member of class oracle.jdbc.driver.OracleTypes with modifiers ""

我调用 SP 的 Dao 类

Query q = session.getCurrentSession().getNamedQuery("callStockStoreProcedure");

实体类

@javax.persistence.NamedNativeQuery(name = "callStockStoreProcedure", query = "{ call TESTP(?) }", resultClass = Quotations.class, hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })

及流程

CREATE OR REPLACE PROCEDURE TESTP 
(
p_cursor out sys_refcursor
) AS

begin
open p_cursor for SELECT * FROM MF_ITEM_TYPE;

END TESTP;

最佳答案

oracle.jdbc.driver.OracleTypes 包已在 11g 中弃用,并由 oracle.jdbc.OracleTypes 替代

解决方法是创建自定义 Oracle Dialect 并使用 ./core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java 作为示例并进行更改

Class types = ReflectHelper.classForName("oracle.jdbc.driver.OracleTypes");
oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());

Class types = ReflectHelper.classForName("oracle.jdbc.OracleTypes");
oracletypes_cursor_value = types.getField("CURSOR").getInt(null);

或者,如果可能的话,降级 oracle 驱动程序版本。

关于java.lang.IllegalAccessException : When calling stored procedure from Hibhernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28009479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com