-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue with Multiple OnetoMany Relation
PostPosted: Fri Apr 09, 2010 2:12 am 
Newbie

Joined: Fri Apr 09, 2010 1:59 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.