[英]JPA and ORACLE function: error when call a stored procedure using NamedNativeQuery
I have an Oracle function我有一个 Oracle 函数
CREATE OR REPLACE FUNCTION SOL.UPDATE_LD_OAUDITORID (
vCUSTOMERID NUMBER,
vAPPOINTOFCAID NUMBER,
vAUDITORID NUMBER,
vOAUDITORID NUMBER)
RETURN NUMBER
IS
PRAGMA AUTONOMOUS_TRANSACTION;
vGROUPID NUMBER;
rTN NUMBER;
CURSOR c
IS
SELECT COMPANYID,
GROUPID,
PERIODID,
PROCESSID,
CUSTOMERID,
APPOINTOFCAID,
AUDITORID
FROM LIQUIDATIONSDETAILS
WHERE CUSTOMERID = vCUSTOMERID
AND APPOINTOFCAID = vAPPOINTOFCAID
AND AUDITORID = vAUDITORID
AND ( PERIODID = fn_periodcurrent
AND PROCESSID = FN_PROCESSCURRENT
OR PERIODID = fn_periodNEXT AND PROCESSID = FN_PROCESSNEXT) FOR UPDATE;
TYPE nt_type IS TABLE OF c%ROWTYPE;
l_arr nt_type;
DML_ERRORS EXCEPTION;
PRAGMA EXCEPTION_INIT (DML_ERRORS, -24381);
l_errors NUMBER;
errorCnt NUMBER;
errString VARCHAR2 (4000);
l_idx NUMBER;
BEGIN
SELECT FN_CURRENTGROUP (vOAUDITORID) INTO vGROUPID FROM DUAL;
OPEN c;
LOOP
FETCH c
BULK COLLECT INTO l_arr
LIMIT 500;
EXIT WHEN l_arr.COUNT = 0;
BEGIN
FORALL i IN 1 .. l_arr.COUNT SAVE EXCEPTIONS
UPDATE liquidationsdetails
SET groupid = vgroupid, auditorid = vOAUDITORID
WHERE COMPANYID = l_arr (i).COMPANYID
AND GROUPID = l_arr (i).GROUPID
AND PERIODID = l_arr (i).PERIODID
AND PROCESSID = l_arr (i).PROCESSID
AND CUSTOMERID = l_arr (i).CUSTOMERID
AND APPOINTOFCAID = l_arr (i).APPOINTOFCAID
AND AUDITORID = l_arr (i).AUDITORID;
RTN := 1;
EXCEPTION
WHEN dml_errors
THEN -- Now we figure out what failed and why.
errorCnt := SQL%BULK_EXCEPTIONS.COUNT;
errString :=
'Number of statements that failed: ' || TO_CHAR (errorCnt);
RTN := 0;
END;
END LOOP;
CLOSE C;
COMMIT;
RETURN RTN;
END;
/
A dummy entity bean with namednativequery the call of the function一个带有namednativequery 函数调用的虚拟实体bean
@Entity
@NamedNativeQueries({
@javax.persistence.NamedNativeQuery(name = "updateldoauditorid", query = ""
+ "{? = call UPDATE_LD_OAUDITORID(:customerid, :appointofcaid, :auditorid, :oauditorid)}", resultClass = DummyEntity.class,
hints = {
@javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true")})})
public class DummyEntity implements Serializable {
...
a stateless session无状态会话
@Override
public int spUpdate_ld_oauditorid(String customerid, String appointofcaid, String auditorid, String oauditorid) {
Integer isup = (Integer) em.createNamedQuery("updateldoauditorid")
.setParameter(customerid, customerid)
.setParameter(appointofcaid, appointofcaid)
.setParameter(auditorid, auditorid)
.setParameter(oauditorid, oauditorid)
.getSingleResult();
return isup;
}
a jsp page that call the following调用以下内容的jsp页面
try {
update = dummyFacade.spUpdate_ld_oauditorid(customerid, appointofcaid, auditorid, oauditorid);
} catch (Exception ex) {
ex.printStackTrace();
}
I am getting the error我收到错误
java.lang.NullPointerException at org.apache.jsp.members.appointsofcas.liquidations.liquidations_005fa_005foauditorid_jsp.Updateldoauditorid(liquidations_005fa_005foauditorid_jsp.java:96) at org.apache.jsp.members.appointsofcas.liquidations.liquidations_005fa_005foauditorid_jsp._jspService(liquidations_005fa_005foauditorid_jsp.java:415) when execute the jsp page显示java.lang.NullPointerException在org.apache.jsp.members.appointsofcas.liquidations.liquidations_005fa_005foauditorid_jsp.Updateldoauditorid(liquidations_005fa_005foauditorid_jsp.java:96)在org.apache.jsp.members.appointsofcas.liquidations.liquidations_005fa_005foauditorid_jsp._jspService(liquidations_005fa_005foauditorid_jsp.java:415 ) 执行jsp页面时
In your stateless session bean, you are setting the parameters incorrectly.在您的无状态会话 bean 中,您错误地设置了参数。 You are using the value of the parameter twice, you probably forgot the ""
for the first parameter when you called to setParameter()
.您使用了两次参数值,您可能在调用setParameter()
时忘记了第一个参数的""
。
@Override
public int spUpdate_ld_oauditorid(String customerid, String appointofcaid, String auditorid, String oauditorid) {
Integer isup = (Integer) em.createNamedQuery("updateldoauditorid")
.setParameter("customerid", customerid)
.setParameter("appointofcaid", appointofcaid)
.setParameter("auditorid", auditorid)
.setParameter("oauditorid", oauditorid)
.getSingleResult();
return isup;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.