@Entity
Class A{
//assume proper annotations present
private Long id;
@OneToMany(@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<B> b;
//all getters and setters are present...
}
代码:
A a =//get a from data base using hibernate by id
//a contains b also
a.setId(null);
entityDao.persist(a);//line at which i am getting exception
例外:
Caused by: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: B
当使用merge而不是persist时,一切正常。但我想知道持续存在的问题是什么?