我有很多这样的关系:
public class ClassExample1 implements Serializable {
@ManyToMany
@JoinTable(name = "ManyToManyTable", joinColumns = {
@JoinColumn(name = "ClassExample1_ID")}, inverseJoinColumns = {
@JoinColumn(name = "ClassExample3_ID")})
@OrderBy("name ASC")
private Set<ClassExample3> listExample;
... Getters, setters and other variables
}
public class ClassExample3 implements Serializable {
private String name;
...
}
一切正常但是当设置persistence.xml show_sql = true
中的数据库日志时,我注意到当我保存ClassExample1
只是为了更新列表时,hibernate会对ClassExample1
执行更新太。
无论如何都要从ClassExample1
实例保存更新的listExample并避免对ClassExample1
本身进行不必要的更新?
我试过了: 创建另一个类只是为了映射ManyToMany关系,但是这样做我做了hibernate本身可以做的不必要的努力,但我必须控制删除和插入关联。