获取EAGER的问题

时间:2012-08-15 11:32:24

标签: jpa

我使用jpa hibernate 我尝试开发三个类:

但是我有与获取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
}

专长.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
}

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
}

但是当我在jboss中运行这个类时,这个错误被显示

Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags

1 个答案:

答案 0 :(得分:0)

这是因为

的专业知识实体中的Eager fetch
  @ManyToMany(mappedBy="expertises",fetch=FetchType.EAGER)
    private List<TechnicalSkill> technicalSkills=new ArrayList<TechnicalSkill>();

删除Eager fetch,它会起作用。