我很难调试为什么JPA没有联合我的@ManyToMany关系。我发现的所有答案都与丢失的级联语句有关。但我确实拥有它们仍然得到:
引起:org.hibernate.TransientObjectException:对象引用 未保存的瞬态实例 - 之前保存瞬态实例 flushing:com.example.iaa.model.Employee
Thread
答案 0 :(得分:1)
如链接中所示,我改为
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "employee_role", joinColumns = @JoinColumn(name = "id_employee", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "id_role", referencedColumnName = "id"))
private Set<Employee> employees;
和
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "employees")
private Set<Role> roles;
还添加了默认构造函数和eager fetch,然后就可以了。