SQL データベースにクエリを実行する Web アプリを作成しています。私は、エンティティ クラスとファサード クラスを使用して、サイト全体で永続性を確保する必要があるという印象を受けています。エンティティクラステンプレートにはハッシュコードがあり、1.) 必要かどうかわかりません.2.) 必要な場合は int が必要ですが、私が持っているのは文字列だけなので、それらを int に変換してから文字列に戻すにはどうすればよいですか? サイトに表示するには String 値が必要であり、ハッシュには int が必要なためです。
コードは次のとおりです(無実の人を保護するためにインポートは削除されています...):
@Embeddable
public class ComputerOwnersPK implements Serializable {
@Basic(optional=false)
@NotNull
@Column(name="Computer_Name")
private int computerNameId;
@Basic(optional=false)
@NotNull
@Column(name="User_ID")
private int userId;
public ComputerOwnersPK() {
}
public ComputerOwnersPK(int computerNameId,int userId) {
this.computerNameId=computerNameId;
this.userId=userId;
}
public int getComputerNameId() {
return computerNameId;
}
public void setComputerNameId(int computerNameId) {
this.computerNameId=computerNameId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId=userId;
}
@Override
public int hashCode() {
int hash=0;
hash+=(int) computerNameId;
hash+=(int) userId;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if(!(object instanceof ComputerOwnersPK)) {
return false;
}
ComputerOwnersPK other=(ComputerOwnersPK) object;
if(this.computerNameId!=other.userId) {
return false;
}
if(this.userId!=other.userId) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.ComputerOwnersPK[ computerNameId="+computerNameId+", userId="+userId+" ]";
}
}