我有这样的实体模型(使用 EclipseLink 和 JPA 2.0):
@Entity
class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
//equals, hashCode autogenerated by nb.
}
和:
@Entity
class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@ManyToOne
A a;
//equals, hashCode autogenerated by nb.
}
我查询 A 类型的所有对象和 B 类型的所有对象,它们在 Ba 字段上没有空引用。所有对象都被管理。例如,让Collection<A> aObjects, Collection<B> bObjects
.
考虑到aObjects.get(0).equals(bObjects.get(0).a)
和a != null
。我怎样才能确保这一点aObjects.get(0) == bObjects.get(0).a
?
我有相等/相同的对象,但我更喜欢相同的对象。