0

我使用 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
4

1 回答 1

0

这是因为专业实体中的 Eager fetch

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

删除 Eager fetch 即可。

于 2012-08-15T12:00:10.887 回答