equals和hashCode方法重写 以及hibernate的联合主键生成策略的生成类的生成

package com.dada.hibernate;

/**
 * TeacherId entity. @author MyEclipse Persistence Tools
 */

public class TeacherId implements java.io.Serializable {

// Fields

private Integer id;
private String name;
private String title;

// Constructors

/** default constructor */
public TeacherId() {
}

/** full constructor */
public TeacherId(Integer id, String name, String title) {
this.id = id;
this.name = name;
this.title = title;
}

// Property accessors

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}


public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof TeacherId))
return false;
TeacherId castOther = (TeacherId) other;

return 
((this.getId() == castOther.getId()) || (this.getId() != null && castOther.getId() != null && this.getId().equals(castOther.getId())))
&& ((this.getName() == castOther.getName()) || (this.getName() != null && castOther.getName() != null && this.getName().equals(castOther.getName())))
&& ((this.getTitle() == castOther.getTitle()) || (this.getTitle() != null && castOther.getTitle() != null && this.getTitle().equals(castOther.getTitle())));
}

public int hashCode() {
int result = 17;

result = 37 * result + (getId() == null ? 0 : this.getId().hashCode());
result = 37 * result + (getName() == null ? 0 : this.getName().hashCode());
result = 37 * result + (getTitle() == null ? 0 : this.getTitle().hashCode());
return result;
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值