Hibernacja równa się i proxy

Mam jedną wartość BaseEntity, która streszcza właściwość id i version. ta klasa implementuje również hashcode i równa się na podstawie właściwości PK (id).

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


}

teraz dwie jednostki A i B rozszerzają wartość BaseEntity jak poniżej

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;

zamknij sesję załaduj leniwym b i spróbuj a1.getB (). równa się (b1) daje fałsz, ale jeśli porównuję z a1.getB (). getId (). równa się (b1.getId ()), a potem daje prawdziwe dziwne !! Myślę, że to z powodu obiektu proxy proxy java, w każdym razie, aby rozwiązać ten problem?

questionAnswers(4)

yourAnswerToTheQuestion