ID とバージョンのプロパティを抽象化する BaseEntity が 1 つあります。このクラスは、PK (id) プロパティに基づいて hashcode と equals も実装します。
BaseEntity{
Long id;
Long version;
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseEntity other = (BaseEntity) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
現在、2 つのエンティティ A と B は、以下のように BaseEntity を拡張しています。
A extends BaseEntity{
`B b`
B getB(){return b;)
void setB(B b){this.b=b;}
}
B extends BaseEntity{
}
object b1;
object a1;
a1.set(b1);
session.save(a1) //cascade save;
セッションを閉じて a を lazy b でロードし、a1.getB().equals(b1) を試してみると false になりますが、a1.getB().getId().equals(b1.getId()) と比較すると true が返されます。とにかくこれを解決するには、Javaアシストプロキシオブジェクトが原因だと思いますか?