我们开始收到异常“找到同一集合的两个表示形式: models.CompanyDbo.users”
该字段的相关代码为
//code inside the CompanyDbo bean....
@OneToMany(mappedBy="company")
private List<UserDbo> users = new ArrayList<UserDbo>();
//code inside the UserDbo mapping back to Company
@ManyToOne
@JoinColumn(nullable=false)
private CompanyDbo company;
//code inside the controller (and the failure happens on commit)....
CompanyDbo companyDbo = new CompanyDbo();
companyDbo.setSoftwareType(softwareType);
user.setManager(user);
user.setRole(Role.ADMIN);
//NEXT TWO lines set both ends of the association...(not that it is completely necessary since there is only one FK really in the UserDbo table).
user.setCompany(companyDbo);
companyDbo.addUser(user);
JPA.em().persist(companyDbo);
JPA.em().persist(user);
JPA.em().flush();
我需要做哪些更改才能让它正常工作?我读过一些人有级联,但我没有任何地方有级联。
发布于 2013-11-25 19:38:57
结果是调用flush,然后commit和commit调用flush,但在第二次调用时失败(会话是同一个实例)。也许这是一个4.1.3的bug或者别的什么。
嗯,然后在第二次刷新调用时修改代码失败(这应该是允许的,尽管它不会刷新太多)……
JPA.em().persist(companyDbo);
JPA.em().persist(user);
JPA.em().flush();
JPA.em().flush(); //now this fails
院长
https://stackoverflow.com/questions/20199895
复制