2013-05-21 59 views
2

我知道GAE上XG交易有5個實體組的限制,但我認爲我在一次交易中只使用3組(商品,類別,商品類別)並仍然得到這個異常: 引起:java.lang.IllegalArgumentException:在單個事務中操作太多的實體組。GAE,JPA,XG交易,太多的實體組異常

這裏是我的數據模型的代碼和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); 
} 

商品分類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; 
} 

任何想法,爲什麼這不應該工作?

感謝您的任何答案!

Pobo

回答

1

我有類似的問題。我試圖獲得超過5個相同的實體!從GAE Datastore鍵入並獲得太多的實體組異常。所以我認爲它不依賴於不同的類型,而是依賴於持久性實體。因爲同一類型的每個對象都有不同的實體組。當試圖進行交易時,你遇到問題的所有對象。因此,對於獲得我不使用交易實體的名單了

和它的作品

+0

感謝您的回覆,但是當我堅持新CommodityCategory對象時發生的錯誤。而且只有1個類別對象和1個商品對象,所以5 +就不會有問題。我不使用事務來檢索列表。 – Pobo