Reputation: 21
I know there is limit of 5 entity groups in XG-transaction on GAE but I think I am using only 3 groups(Commodity, Category, CommodityCategory) in one transaction and still getting this exception: Caused by: java.lang.IllegalArgumentException: operating on too many entity groups in a single transaction.
Here are vital parts of code of my datamodel and dao:
Category model
@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);
}
Commodity model
@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 model
@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 implementation
@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;
}
Any ideas why this shouldn't work?
Thanks for any answer!
Pobo
Upvotes: 2
Views: 649
Reputation: 2000
I've got a similar problem. I try to get more than 5 entities of the same! type from GAE Datastore and get too many entity groups exception. So I think it doesnt depend on different types but on amout of persistence entity. Because each object of the same type has different entity group. When tried to get in transaction all of the object you have the problem .
So for getting list of the entity I don't use transaction anymore and it works
Upvotes: 1