我们开始获得异常“找到两个相同集合的表示: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();
我需要更改才能使其正常工作?我读过有些人已经级联,但我没有在任何地方进行级联。
答案 0 :(得分:0)
结果是调用flush然后提交和提交调用flush,第二次调用失败(会话是同一个实例)。也许这是一个4.1.3的bug或者什么。
嗯,然后在第二次刷新调用时将代码修改为此失败(虽然它不会冲洗太多但应该允许这样做)...JPA.em().persist(companyDbo);
JPA.em().persist(user);
JPA.em().flush();
JPA.em().flush(); //now this fails
迪安