我无法使用注释从hibernate调用SP。每次我调用SP休眠显示错误为
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;
答案 0 :(得分:1)
此异常类似于Hibernate错误:https://hibernate.atlassian.net/browse/HHH-3682, https://hibernate.atlassian.net/browse/HHH-3449
修复您可以找到的版本: https://hibernate.atlassian.net/browse/HHH-3159
答案 1 :(得分:0)
oracle.jdbc.driver.OracleTypes包已在11g中弃用,并替换为oracle.jdbc.OracleTypes
解决方法是创建自定义Oracle方言并使用./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驱动程序版本。