gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:32:22 26 4
gpt4 key购买 nike

我知道在 GAE 上的 XG 交易中有 5 个实体组的限制,但我认为我在一次交易中只使用了 3 个组(商品、类别、商品类别),但仍然出现此异常:Caused by: 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;
}

知道为什么这不起作用吗?

感谢您的回答!

波波

最佳答案

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

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

关于java - GAE、JPA、XG-transactions、太多实体组异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16675041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com