调用oracle存储过程时出现以下错误
异常说明:从行读取的主键[DatabaseRecord( retval =>空值 error_message =>检测到执行期间检测到null为空。主 键不能包含null。 查询:ReadAllQuery(name =" CCM_ASSIGN_LOOP" referenceClass = CcmAssignLoop)
我的实体
@Entity
@NamedStoredProcedureQuery(name="CCM_ASSIGN_LOOP", procedureName="TCS.CCM_ASSIGN_LOOP", resultClass=CcmAssignLoop.class,
parameters={
@StoredProcedureParameter(queryParameter="psubno",name="psubno",direction=Direction.IN),
@StoredProcedureParameter(queryParameter="upd_user",name="upd_user",direction=Direction.IN),
@StoredProcedureParameter(queryParameter="ccloop_in",name="ccloop_in",direction=Direction.IN),
@StoredProcedureParameter(queryParameter="ccstage_in",name="ccstage_in",direction=Direction.IN),
@StoredProcedureParameter(queryParameter="retval",name="retval",direction=Direction.OUT),
@StoredProcedureParameter(queryParameter="error_message",name="error_message",direction=Direction.OUT)
}
)
public class CcmAssignLoop implements Serializable {
private static final long serialVersionUID = 1L;
public CcmAssignLoop() {
super();
}
@Id
private String psubno;
private String upd_user;
private String ccloop_in;
private BigDecimal ccstage_in;
private String retval;
private String error_message;
public String getPsubno() {
return psubno;
}
public void setPsubno(String psubno) {
this.psubno = psubno;
}
public String getUpd_user() {
return upd_user;
}
public void setUpd_user(String upd_user) {
this.upd_user = upd_user;
}
public String getCcloop_in() {
return ccloop_in;
}
public void setCcloop_in(String ccloop_in) {
this.ccloop_in = ccloop_in;
}
public BigDecimal getCcstage_in() {
return ccstage_in;
}
public void setCcstage_in(BigDecimal ccstage_in) {
this.ccstage_in = ccstage_in;
}
public String getRetval() {
return retval;
}
public void setRetval(String retval) {
this.retval = retval;
}
public String getError_message() {
return error_message;
}
public void setError_message(String error_message) {
this.error_message = error_message;
}
}
以下是调用存储过程的代码
Query q = tabsEm.createNamedQuery("CCM_ASSIGN_LOOP");
q.setParameter("psubno", subno);
q.setParameter("upd_user", "abc");
q.setParameter("ccloop_in", "xyz");
q.setParameter("ccstage_in", new BigDecimal(5));
// CcmAssignLoop ccmAssignLoop = (CcmAssignLoop)q.getSingleResult();
q.getResultList();
上面提到的列不是主键,我收到此错误。
更新
我在oracle上的程序就像
一样CREATE OR REPLACE PROCEDURE TCS.CCM_ASSIGN_LOOP(PSUBNO IN VARCHAR2, UPD_USER IN VARCHAR2, CCLOOP_IN IN VARCHAR2, CCSTAGE_IN IN NUMBER, RETVAL OUT VARCHAR2, ERROR_MESSAGE OUT VARCHAR2)
IS
OLD_CCSTAGE CCM_USER_INFO.CCLOOP_STAGE%TYPE;
OLD_CCLOOP CCM_USER_INFO.CCLOOP%TYPE;
PROC_CONTRNO CRM_USER_INFO.CONTRNO%TYPE;
TEMP_COUNT NUMBER;
RET_VAL VARCHAR2(100);
V_ERROR_MESSAGE VARCHAR2(256);
我可以看到RETVAL和RET_VAL,这可能是因为这个错误吗?
此致
答案 0 :(得分:0)
可能是区分大小写的问题。尝试将queryParameter
属性值全部设为大写,例如:
@StoredProcedureParameter(queryParameter="PSUBNO",name="psubno",direction=Direction.IN),
我认为,如果您没有使用Column
注释指定名称,则默认情况下数据库列名称(以及存储过程参数)是大写的。
答案 1 :(得分:0)
您正在设置“resultClass = CcmAssignLoop.class”,这意味着该过程将返回数据以构建此类的实例,您的过程没有,所以不要设置它。然后你将获得原始数据。