`

“cannot simultaneously fetch multiple bags”的解决方法

JPA 
阅读更多
@OneToMany(mappedBy = "customer",cascade = {CascadeType.ALL},fetch = FetchType.LAZY)
private Collection<CartItem> cartItems;
	
@OneToMany(mappedBy = "customer",cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
private Collection<BookOrder> orders ; 


在用JPA进行注释时,如果一个实体里要映射多个集合实体时,我们不能把两个集合的的FetchType设置为EAGER,此时只能设置为LAZY,否则会报:cannot simultaneously fetch multiple bags。或者我们也可以借助:@IndexColumn
分享到:
评论
7 楼 cylove007 2011-07-25  
多的一方不用List,用Set就没问题的
6 楼 BestUpon 2010-02-25  
我也遇到了这样的问题!  /**
     * 需要测评的所有项目
    */
    @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinTable(name = "tbl_voteResult_project", joinColumns = { @JoinColumn(name = "voteResultID", referencedColumnName = "voteResultID") }, inverseJoinColumns = { @JoinColumn(name = "projectID", referencedColumnName = "projectID") })
    private List<Project> projects = new ArrayList<Project>();

在另一端使用的:
// 投票结果
@ManyToMany(mappedBy = "projects")
private List<VoteResult> voteResults = new ArrayList<VoteResult>();
才解决了
谢谢诶兄台了
5 楼 yyyyy5101 2009-05-20  
3楼的问题怎么弄,我现在就是这个问题!!
4 楼 liuzhenwen 2008-12-21  
@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "I2D_SYSID")
    @Column(name = "I2D_SYSID")
public Integer getId() {
return id;
}

@Column(name = "ISV2DEC")
public String getIsv2Dec() {
return isv2Dec;
}
@Column(name = "DEC2ISV")
public String getDec2Isv() {
return dec2Isv;
}
@Column(name = "add_time")
public String getAddTime() {
return addTime;
}
@Column(name = "edit_time")
public String getEditTime() {
return editTime;
}

@Column(name = "isprop")
public String getIsProp() {
return isProp;
}
@Column(name = "isleaf")
public String getIsLeaf() {
return isLeaf;
}
@Column(name = "isInDec")
public String getIsInDec() {
return isInDec;
}
@Column(name = "status")
public String getStatus() {
return status;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "add_userid")
public SysUser getAddUser() {
return addUser;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "edit_userid")
public SysUser getEditUser() {
return editUser;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "parent_map_sysid")
public DecIsv2DecMap getParentMap() {
return parentMap;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "DECS_SYSID")
public DecSchema getDecSchema() {
return decSchema;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ISVSCHEMA_SYSID")
public IsvSchema getIsvSchema() {
return isvSchema;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PF_SYSID")
public DecPublicField getDecPublicField() {
return decPublicField;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parentMap",cascade=CascadeType.ALL)
@JoinColumn(name = "parent_map_sysid")
public List<DecIsv2DecMap> getMapList() {
return mapList;
}

我的时这样的结构,一个实体类中存在多个多对一和一个一对多的关系,但是在从DB中获取对象后,在取mapList中的值时,它时null但是里面有数据,请问这个问题如何处理
3 楼 liuzhenwen 2008-12-21  
设置成lazy时,在从对象中取cartItems中的对象时,没有取到,如何处理?
2 楼 anzn20 2008-10-23  
你真的很牛鼻。谢谢咯
1 楼 lchlrb 2008-05-17  
  谢谢你,很强悍。。。

相关推荐

Global site tag (gtag.js) - Google Analytics