我遇到了一个奇怪的问题,Hibernate 3,一个具有空值的表。当我尝试从DB中选择行时,我得到以下异常:
将空值分配给基本类型setter的属性。
最常见的修复方法似乎是将原始值更改为对象,事情是它们已经是对象。这是我的代码:
package model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
private long pk;
private Date instant;
private String server;
private String ucid;
private String routingVdn;
private String originalCli;
private String originalDnis;
private String terminatingStation;
private String terminatingAgent;
private Date phase1Instant;
private Integer phase1InternalResultCode;
private Integer phase1ExternalResultCode;
private String phase1Message;
private Date phase2Instant;
private Integer phase2InternalResultCode;
private Integer phase2ExternalResultCode;
private String phase2Message;
@Id
@Column( name = "PK")
@GeneratedValue(strategy=GenerationType.AUTO)
public long getPk() {
return pk;
}
public void setPk(long pk) {
this.pk = pk;
}
@Column( name = "Instant")
@Temporal(TemporalType.TIMESTAMP)
public Date getInstant() {
return instant;
}
public void setInstant(Date instant) {
this.instant = instant;
}
@Column( name = "Ucid")
public String getUcid() {
return ucid;
}
public void setUcid(String ucid) {
this.ucid = ucid;
}
@Column( name = "Routing_Vdn")
public String getRoutingVdn() {
return routingVdn;
}
public void setRoutingVdn(String routingVdn) {
this.routingVdn = routingVdn;
}
@Column( name = "Original_Cli")
public String getOriginalCli() {
return originalCli;
}
public void setOriginalCli(String originalCli) {
this.originalCli = originalCli;
}
@Column( name = "Original_Dnis")
public String getOriginalDnis() {
return originalDnis;
}
public void setOriginalDnis(String originalDnis) {
this.originalDnis = originalDnis;
}
@Column( name = "Terminating_Station")
public String getTerminatingStation() {
return terminatingStation;
}
public void setTerminatingStation(String terminatingStation) {
this.terminatingStation = terminatingStation;
}
@Column( name = "Terminating_Agent")
public String getTerminatingAgent() {
return terminatingAgent;
}
public void setTerminatingAgent(String terminatingAgent) {
this.terminatingAgent = terminatingAgent;
}
@Column(name = "Phase_1_Instant")
@Temporal(TemporalType.TIMESTAMP)
public Date getPhase1Instant() {
return phase1Instant;
}
public void setPhase1Instant(Date phase1Instant) {
this.phase1Instant = phase1Instant;
}
@Column(name = "Phase_1_Internal_Result_Code")
public Integer getPhase1InternalResultCode() {
return phase1InternalResultCode;
}
public void setPhase1InternalResultCode(Integer phase1InternalResultCode) {
this.phase1InternalResultCode = phase1InternalResultCode;
}
@Column(name = "Phase_1_External_Result_Code")
public Integer getPhase1ExternalResultCode() {
return phase1ExternalResultCode;
}
public void setPhase1ExternalResultCode(int phase1ExternalResultCode) {
this.phase1ExternalResultCode = phase1ExternalResultCode;
}
@Column(name = "Phase_1_Message")
public String getPhase1Message() {
return phase1Message;
}
public void setPhase1Message(String phase1Message) {
this.phase1Message = phase1Message;
}
@Column(name = "Phase_2_Instant")
@Temporal(TemporalType.TIMESTAMP)
public Date getPhase2Instant() {
return phase2Instant;
}
public void setPhase2Instant(Date phase2Instant) {
this.phase2Instant = phase2Instant;
}
@Column(name = "Phase_2_Internal_Result_Code")
public Integer getPhase2InternalResultCode() {
return phase2InternalResultCode;
}
public void setPhase2InternalResultCode(Integer phase2InternalResultCode) {
this.phase2InternalResultCode = phase2InternalResultCode;
}
@Column(name = "Phase_2_External_Result_Code")
public Integer getPhase2ExternalResultCode() {
return phase2ExternalResultCode;
}
public void setPhase2ExternalResultCode(Integer phase2ExternalResultCode) {
this.phase2ExternalResultCode = phase2ExternalResultCode;
}
@Column(name = "Phase_2_Message")
public String getPhase2Message() {
return phase2Message;
}
public void setPhase2Message(String phase2Message) {
this.phase2Message = phase2Message;
}
@Column(name = "Server")
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
}
}
在“phase1InternalResultCode”的setter上发生异常,在DB中为null。
我在JBoss 5.1.0中运行它并使用Hibernate 3.6.0 Final
答案 0 :(得分:0)
对于它的价值,我已经设法通过将注释放在变量而不是吸气剂上来实现这一点。
这似乎工作正常,但我知道这不是最佳做法。