@Entity
public class A {
//should be mapped by a
public B b1;
//should be mapped by a
public B b2;
}
@Entity
public class B {
@ManyToOne
public A a;
}
我可以实现这样的目标吗?
我知道我可以在 class A
中使用 long b1_id
和 long b2_id
但我只是想看看是否有办法使用该对象马上。
基本上,class A
将恰好有 2 个 class B
实例。它不在集合中,所以我不能使用 @OneToMany
。
B 类
始终映射到单个 A。
数据库表应该是这样的:
A
id | b1_id | b2_id
B
id | a_id
谢谢。
最佳答案
是的,那应该没问题。使用适当的 filter
条件。请引用Hibernate Filters了解更多详情。
关于java - JPA 实体有多个同一类的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12919337/