java.lang.IllegalAccessException:从Hibhernate调用存储过程时

时间:2015-01-18 12:08:04

标签: java hibernate

我无法使用注释从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;

2 个答案:

答案 0 :(得分:1)

答案 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驱动程序版本。