学习JPA又一个错误!

错误名:cannot simultaneously fetch multiple bags
在实体类中映射了几个集合属性,如:
@OneToMany(mappedBy = "customer",cascade = {CascadeType.ALL},fetch = FetchType.EAGER)  
private Collection<User> user;  
      
@OneToMany(mappedBy = "customer",cascade = {CascadeType.ALL},fetch = FetchType.EAGER)  
private Collection<BookOrder> orders ;  

结果Tomcat启动时就报cannot simultaneously fetch multiple bags异常,翻了一下书:在用JPA进行注释时,如果一个实体里要映射多个集合实体时,我们不能把两个集合的的FetchType设置为EAGER,此时只能设置为LAZY,否则会报:cannot simultaneously fetch multiple bags。或者我们也可以借助:@IndexColumn

你可能感兴趣的:(tomcat,jpa)