GAE,JPA,XG-transactions,太多实体组异常

时间:2013-05-21 16:33:21

标签: java google-app-engine jpa datanucleus

我知道GAE上的XG交易中有5个实体组的限制,但我认为我在一个交易中只使用了3个组(商品,类别,商品类别),但仍然遇到此异常: 引起:java.lang.IllegalArgumentException:在单个事务中对太多实体组进行操作。

以下是我的datamodel和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);
}

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;
}

为什么这不起作用的任何想法?

感谢您的回答!

条规管

1 个答案:

答案 0 :(得分:1)

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

因此,为了获取实体的列表,我不再使用事务并且它可以工作