Ruhezustand gleich und Proxy

Ich habe eine BaseEntity, die ID- und Versionseigenschaft abstrahiert. Diese Klasse implementiert auch Hashcode und entspricht der PK (id) -Eigenschaft.

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;
}


}

Jetzt erweitern zwei Entitäten A und B die Basisentität wie folgt

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;

schließe die Session lade a mit Lazy b und versuche a1.getB (). equals (b1) gibt false, aber wenn ich mit a1.getB (). getId (). equals (b1.getId ()) vergleiche, dann gibt es true strange !! Ich denke, es liegt an Java-Assist-Proxy-Objekt, trotzdem, um dieses Problem zu lösen?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage