【问题标题】:Primary Key null error in @NamedStoredProcedureQuery for eclipselinkeclipselink 的 @NamedStoredProcedureQuery 中的主键空错误
【发布时间】:2013-05-20 15:27:36
【问题描述】:

我在调用 oracle 存储过程时遇到以下错误

异常说明:从行[DatabaseRecord( retval => null error_message => null)] 在执行查询期间被检测为 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,这可能是因为这个错误吗?

问候,

【问题讨论】:

    标签: java jpa eclipselink


    【解决方案1】:

    您正在设置“resultClass=CcmAssignLoop.class”,这意味着程序将返回数据来构建此类的实例,您的程序没有,所以不要设置。然后你将得到原始数据。

    【讨论】:

      【解决方案2】:

      这可能是区分大小写的问题。尝试将queryParameter 属性值全部大写,例如:

      @StoredProcedureParameter(queryParameter="PSUBNO",name="psubno",direction=Direction.IN),
      

      我在想,如果您不使用 Column 注释指定名称,数据库列名(以及存储过程参数)默认为大写。

      【讨论】:

      • 我根据您的建议做了更改,但仍然是同样的错误。
      猜你喜欢
      • 1970-01-01
      • 2012-09-07
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 2012-06-03
      相关资源
      最近更新 更多