&& ((this.getVarcName() == castOther.getVarcName()) || (this.getVarcName() != null
&& castOther.getVarcName() != null && this.getVarcName().equals(castOther.getVarcName())))
&& ((this.getVarcAddress() == castOther.getVarcAddress()) || (this.getVarcAddress() != null
&& castOther.getVarcAddress() != null && this.getVarcAddress().equals(
castOther.getVarcAddress()))) && (this.getIntAge() == castOther.getIntAge());
}
public int hashCode() {
int result = 17;
result = 37 * result + this.getIntId();
result = 37 * result + (getVarcName() == null 0 : this.getVarcName().hashCode());
result = 37 * result + (getVarcAddress() == null 0 : this.getVarcAddress().hashCode());
result = 37 * result + this.getIntAge();
return result;
}
}
3. 可能还会出现的问题
具体来说问题就是查询出来的结果列表为‘null’(这一点我这次在我机器上测试时没有出现)。
如果出现了该问题,那么看到这一点就应该能解决问题啦,如果不出现那就更好,呵呵!
但是个人觉得这一点应该还是得说的。^_^
有时候查询出来的结果列表为‘null’,这令人很是费解,可以想下这是什么原因?
直接上原因,嘎嘎……。
原因:作为联合主键的字段理论上不应该包含可能为空的字段。
原因分析:根据原因,说明实体Bean中的某个(些)对应的表字段有空值。
解决方案:只需要将可能为空的字段不作为联合主键的一部分就可以。
说的估计晕头了吧,直接来个事例吧(个人一直觉得,例子是解释问题的最好说明)。
假设表中的varcName和varcAddress是可能为空的,其它都不可能为空,那么映射应该是这样的
User.java
[java]
……
private UserId id;
private String varcName;
private String varcAddress;
……
/*
这里加入varcName和varcAddress映射内容,嗯还是贴出来吧,反正电子档的又不怕木有地方,嘎嘎……
*/
@Column (name="varcName", length=50)
public String getVarcName() {
return this.varcName;
}
public void setVarcName(String varcName) {
this.varcName = varcName;
}
@Column (name="varcAddress", length=50)
public String getVarcAddress() {
return this.varcAddress;
}
public void setVarcAddress(String varcAddress) {
this.varcAddress = varcAddress;
}
……
private UserId id;
private String varcName;
private String varcAddress;
……
/*
这里加入varcName和varcAddress映射内容,嗯还是贴出来吧,反正电子档的又不怕木有地方,嘎嘎……
*/
@Column(name="varcName", length=50)
public String getVarcName() {
return this.varcName;
}
public void setVarcName(String varcName) {
this.varcName = varcName;
}
@Column(name="varcAddress", length=50)
public String getVarcAddress() {
return this.varcAddress;
}
public void setVarcAddress(String varcAddress) {
this.varcAddress = varcAddress;
}
UserId.java
[java] view plain copy print
……
private int intId;
private int intAge;
……