我遇到了一个无法理解的问题。我真的希望那里有人可以提供帮助。
由于我的数据模型表示编程对象,因此这可能会有点元。我有三个实体:Program、Clazz 和 Method。类可以有多个方法,偶尔会继承一些其他方法(从其他类)。
@Entity
public class Program {
@OneToMany(mappedBy="program", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@OrderBy("name ASC")
private Set<Clazz> clazzes = new TreeSet<Clazz>();
}
@Entity
public class Clazz {
@ManyToOne
private Program program;
@OneToMany(mappedBy="clazz", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@OrderBy("name ASC")
private Set<Method> methods = new TreeSet<Method>();
@ManyToMany(fetch=FetchType.LAZY, mappedBy="inheritedBy")
@OrderBy("name ASC")
private Set<Method> inheritedMethods = new TreeSet<Method>();
@PreRemove
private void tearDown() {
inheritedMethods.clear();
}
}
@Entity @Table(name="sf_method")
public class Method {
@ManyToOne(optional=true)
private Clazz clazz;
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name = "sf_method_inherited_by_class",
joinColumns = { @JoinColumn(name = "sf_method_inherited_by_class") …Run Code Online (Sandbox Code Playgroud)