0

I work with jpa hibernate I try to develop three class :

but I have error related to type of fetch EAGER

@Entity
public class Request implements Serializable{


    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer requestId;
    private String detailRequest;

    private String place;



        @ManyToMany(mappedBy="requests",fetch=FetchType.EAGER)
    private List<Expertise> expertises;


...
//getter , setter and constructor
}

the Expertise .java

@Entity
public class Expertise implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
    private int idExpertise;
    private String seniority;
    @ManyToMany(mappedBy="expertises",fetch=FetchType.EAGER)
    private List<TechnicalSkill> technicalSkills=new ArrayList<TechnicalSkill>();


    @ManyToMany
    private List<Request> requests=new ArrayList<Request>();



....
//getter , setter and constructor
}

the TechnicalSkill.java

@Entity
public class TechnicalSkill implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
    private int idTechnicalSkill;
    private String description;
    @ManyToMany
    private List<Expertise> expertises=new ArrayList<Expertise>();

...
//getter , setter and constructor
}

but when I run this class in jboss this error is diplayed

Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
franco10
  • 1
  • 1
  • 3

1 Answers1

0

Its because of the Eager fetch in Expertise entity for

  @ManyToMany(mappedBy="expertises",fetch=FetchType.EAGER)
    private List<TechnicalSkill> technicalSkills=new ArrayList<TechnicalSkill>();

Remove the Eager fetch and it will work.

dhamibirendra
  • 3,016
  • 23
  • 26