当我试图获取我的Employee
实体列表时,我收到了这个错误:
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch
multiple bags
我的Employee
实体类有两个不同对象的列表。我想有问题。
@ManyToMany
@JoinTable(name = "employee_project",
joinColumns = {@JoinColumn(name = "employee_id", referencedColumnName = "employee_id")},
inverseJoinColumns = {@JoinColumn(name = "project_id", referencedColumnName = "project_id")})
protected List<Project> projects;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "employee_id")
protected List<EmployeeTheme> themes;
我的实体Project
目前没有Employee
对象列表。但
public class EmployeeTheme implements Serializable {
@EmbeddedId
private EmployeeTheme PK id;
@ManyToOne
@JoinColumn(name = "employee_id", nullable = false, insertable = false, updatable = false)
protected Employee employee;
}
这是我的复合键类:
@Embeddable
public class EmployeeThemePK implements Serializable {
@Column(name = "employee_id")
protected Long employeeId;
@Column(name = "theme")
protected String theme;
}
如何正确配置这些关系?
编辑
我已将主题和项目的列表切换为设置。我已经从我的 JSON 主题中排除了,现在我遇到了另一个例外。我还在criteria.setFetchMode("projects", FetchMode.JOIN);
我的 DAO 类中添加了方法。
failed to lazily initialize a collection of role: com.package.Employee.projects,
no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a
collection of role: com.package.Employee.projects, no session or session
was closed
Exception caught during request processing: flexjson.JSONException: Error
trying to deepSerialize
flexjson.JSONException: Error trying to deepSerialize