I have three tables EmployeeEntity, LanguageEntity and SkillSetEntity
EmployeeEntity has one to Many relationship with LanguageEntity
EmployeeEntity has one to Many relationship with SkillSetEntity.
When i use two OnetoMany relationship, i get the below error
HibernateException: cannot simultaneously fetch multiple bags
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "EMP_INFO")
public class EmployeeEntity implements Serializable {
private Integer empId;
private String empName;
private List<LanguageEntity> languageEntity;
private List<SkillSetEntity> skillSetEntity;
public EmployeeEntity(){
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column (name="EMP_ID")
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
@Column (name="EMP_NAME")
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER )
@JoinColumn(name="EMP_ID", nullable=false)
public List<LanguageEntity> getLanguageEntity() {
return languageEntity;
}
public void setLanguageEntity(List<LanguageEntity> languageEntity) {
this.languageEntity = languageEntity;
}
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER )
@JoinColumn(name="EMP_ID", nullable=false)
public List<SkillSetEntity> getSkillSetEntity() {
return skillSetEntity;
}
public void setSkillSetEntity(List<SkillSetEntity> skillSetEntity) {
this.skillSetEntity = skillSetEntity;
}
}
Code:
@Entity
@Table (name="EMP_LANGUAGES_INFO")
public class LanguageEntity implements Serializable{
private String languageCode;
private String languageId;
private Integer empId ;
public LanguageEntity(){
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="LANGUAGE_ID")
public String getLanguageId() {
return languageId;
}
public void setLanguageId(String languageId) {
this.languageId = languageId;
}
@Column(name="LANGUAGE_CODE")
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
@Column(name="EMP_ID", insertable=false, updatable=false)
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
}
Code:
@Entity
@Table (name="emp_skillset_info")
public class SkillSetEntity{
private String skillSetCode;
private Integer skillSetId;
private Integer empId ;
public SkillSetEntity(){
}
@Column(name="SKILLSET_CODE")
public String getSkillSetCode() {
return skillSetCode;
}
public void setSkillSetCode(String skillSetCode) {
this.skillSetCode = skillSetCode;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="SKILLSET_ID")
public Integer getSkillSetId() {
return skillSetId;
}
public void setSkillSetId(Integer skillSetId) {
this.skillSetId = skillSetId;
}
@Column(name="EMP_ID", insertable=false, updatable=false)
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
}
Please let me know how to handle multiple OnetoMany relationship in hibernate.