我有3个实体和一个实体用于链接这三个实体:
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "a", fetch = FetchType.LAZY)
private List<ABCXref> abcXref = new ArrayList<ABCXref>();
// getters/setters
}
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "b", fetch = FetchType.LAZY)
private List<ABCXref> abcXref = new ArrayList<ABCXref>();
// getters/setters
}
@Entity
public class C {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "c", fetch = FetchType.LAZY)
private List<ABCXref> abcXref = new ArrayList<ABCXref>();
// getters/setters
}
@Entity
public class ABCXref {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@JoinColumn(name = "A_ID", nullable = true)
@ManyToOne(optional = true, fetch = FetchType.LAZY)
private A a;
@JoinColumn(name = "B_ID")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private B b;
@JoinColumn(name = "C_ID")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private C c;
}
问题是:A,B和C的所有实例是否共享ABCXref's
的相同列表?如果我向ABCXref
实例添加新A
该怎么办?此ABCXref
是否出现在ABCXrefs
和B
的{{1}}列表中?
即。这段代码会输出C
吗?
true