【发布时间】:2018-06-26 08:38:10
【问题描述】:
我在 Hibernate 实体中有这个映射。
A.java
@OneToMany(mappedBy = "a", cascade = CascadeType.ALL)
Set<B> bs;
B.java
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "A_ID")
A a;
我需要对 A 进行编辑。
所以在用Spring @Transactional注解的方法加载实体后
A a = entityManager.find(A.class, a.getId);
// set some new values on the instance variables of a.
// take out the set of Bs through a and delete them
for(B b : a.getBs()) {
entityManager.remove(b);
}
// create new objects of B and add them to the below set-
Set<B> bs = new HashSet<>();
a.setBs(bs);
entityManager.merge(a);
以上代码是单一方法的一部分。
我得到 - 已删除的实例传递给合并。 请提出建议。
【问题讨论】:
标签: java hibernate jpa hibernate-mapping