我知道 GAE 上的 XG 事务中有 5 个实体组的限制,但我认为我在一个事务中只使用 3 个组(商品、类别、商品类别)并且仍然出现此异常: 引起:java.lang.IllegalArgumentException:操作在单个事务中处理过多的实体组。
以下是我的数据模型和 dao 代码的重要部分:
类别型号
@Entity(name = "Category")
public class Category extends BaseDatastoreEntity{
private String name;
private Key parentKey;
private String parentName;
@Unowned
@OneToMany(cascade= CascadeType.ALL)
private Set<CommodityCategory> commodityCategories = new HashSet<CommodityCategory>();
.
.
public void addCommodityCategoryInternal(CommodityCategory commodityCategory) {
this.commodityCategories.add(commodityCategory);
}
商品型号
@Entity(name = "Commodity")
public class Commodity extends BaseDatastoreEntity implements IRateable{
private String name;
private BigDecimal price;
.
.
@OneToMany(mappedBy = "commodity", cascade= CascadeType.ALL, fetch= FetchType.EAGER)
private Set<Picture> pictures = new HashSet<Picture>();
@Unowned
@OneToMany(cascade= CascadeType.ALL)
private Set<CommodityCategory> commodityCategories = new HashSet<CommodityCategory>();
.
.
public void addCommodityCategoryInternal(CommodityCategory commodityCategory) {
this.commodityCategories.add(commodityCategory);
}
商品类别模型
@Entity(name="CommodityCategory")
public class CommodityCategory extends BaseDatastoreEntity{
private boolean isDefaultCategory;
@Unowned
@ManyToOne(cascade= CascadeType.ALL)
private Key commodity;
@Unowned
@ManyToOne(cascade= CascadeType.ALL)
private Key category;
@SuppressWarnings("LeakingThisInConstructor")
public CommodityCategory(boolean isDefaultCategory, Commodity commodity, Category category) {
super(true);
this.isDefaultCategory = isDefaultCategory;
this.commodity = commodity.getId();
this.category = category.getId();
category.addCommodityCategoryInternal(this);
commodity.addCommodityCategoryInternal(this);
}
CommodityCategory DAO 实现
@Repository("commodityCategoryDAOImpl")
public class CommodityCategoryDAOImpl extends AbstractDAO<CommodityCategory, Key> implements CommodityCategoryDAO{
@Override
public CommodityCategory create(boolean isDefaultCategory, Commodity comm, Category cat) {
EntityManager em = EMF.get().createEntityManager();
setEntityManager(em);
getEntityManager().clear();
getEntityManager().getTransaction().begin();
Commodity commodity = getEntityManager().find(Commodity.class, comm.getId());
Category category = getEntityManager().find(Category.class, cat.getId());
CommodityCategory commodityCategory = new CommodityCategory(isDefaultCategory, commodity, category);
getEntityManager().persist(commodityCategory);
getEntityManager().getTransaction().commit();//here is the exception
getEntityManager().clear();
return commodityCategory;
}
任何想法为什么这不应该工作?
感谢您的任何回答!
波波