2

我知道 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;
}

任何想法为什么这不应该工作?

感谢您的任何回答!

波波

4

1 回答 1

1

我有一个类似的问题。我尝试获得超过 5 个相同的实体!从 GAE 数据存储中输入并获得太多实体组异常。所以我认为它不依赖于不同的类型,而是依赖于持久性实体的数量。因为同一类型的每个对象都有不同的实体组。当试图进入事务所有你有问题的对象时。

因此,为了获取实体列表,我不再使用事务并且它有效

于 2013-05-27T07:05:00.857 回答