我正在使用JPA调用oracle存储过程,并获得下面提到的异常
错误
[4/24/14 9:07:37:583 EDT] 00000031 SystemOut O [EL Warning]: 2014-04-24 09:07:37.452--UnitOfWork(1697919964)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'STP_REFRESH_CATEGORY_GUARANTEE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call: BEGIN STP_REFRESH_CATEGORY_GUARANTEE(SHIP_CODE=>?, SAIL_DATE=>?, return_code=>?); END;
bind => [3 parameters bound]
Query: DataReadQuery(name="refreshCategoryGuarantee" )
[4/24/14 9:07:37:584 EDT] 00000031 SystemOut O **********************************************************************************
[4/24/14 9:07:37:584 EDT] 00000031 SystemOut O EXCEPTION: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'STP_REFRESH_CATEGORY_GUARANTEE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call: BEGIN STP_REFRESH_CATEGORY_GUARANTEE(SHIP_CODE=>?, SAIL_DATE=>?, return_code=>?); END;
bind => [3 parameters bound]
Query: DataReadQuery(name="refreshCategoryGuarantee" ) ship_code: AL sail_date: 01-JUN-14
代码:
尝试{查询查询=getEntityManager().createNamedQuery("refreshCategoryGuarante");query.setParameter("SHIP_CODE",SHIP_CODE);query.setParameter("SAIL_DATE",DateUtil.getSqlDate(sailDate));return(Integer)query.getSingleResult();}catch(异常ex){System.out.println("***************************************************************");logger.error("使用param["+ship_code+","+sailDate+"]执行refreshCategoryGuarante命名查询时出错",例如);return存储过程常量.return_CODE_EXCEPTION;}
Here, refreshCategoryGuarantee is named query of STP_REFRESH_CATEGORY_GUARANTEE procedures.
-------------
<pre>
@NamedStoredProcedureQuery(
name="refreshCategoryGuarantee",
procedureName="STP_REFRESH_CATEGORY_GUARANTEE",
returnsResultSet=false,
parameters={
@StoredProcedureParameter(queryParameter="SHIP_CODE", type=String.class),
@StoredProcedureParameter(queryParameter="SAIL_DATE", type=Date.class),
@StoredProcedureParameter(queryParameter="return_code", direction=Direction.OUT, type=Integer.class)
})
我的问题是,当我在oracle中执行下面提到的匿名块时,它的工作没有任何问题
将服务器输出设置为ON声明rc编号;开始STP_REFRESH_CATEGORY_担保('OA','24-jan-15',rc);dbms_output_line('响应代码:'||rc);结束;
我不知道为什么我会在JPA电话中收到这个?你能找个人帮我解决吗?
参数SAIL_DATE在StoredProcedureParameter定义中的类型,是java.util.DATE吗?它必须是java.sql.date…
@StoredProcedureParameter(queryParameter="SAIL_DATE", type=java.slq.Date.class)
这与访问参数有关。不按参数名称。
1-访问EntityManager。例如,通过@PersistenceContext private EntityManager em;
2-使用NUMBERS访问参数。这只是一个例子。
StoredProcedureQuery query = entityManager
.createStoredProcedureQuery("count_comments")
.registerStoredProcedureParameter(
1,Long.class, ParameterMode.IN
)
.registerStoredProcedureParameter(
2,Long.class, ParameterMode.OUT
)
.setParameter(1, 1L);
query.execute();
Long commentCount = (Long) query.getOutputParameterValue(2);