2010-04-08 70 views
0

假设您有一个客户购买卡对象和一个产品对象。 当客户选择购买选择时,您创建该对象,然后添加产品。 它应该是事务性的,但它与产品不在同一个实体组中,并且该卡已被保留,不是吗? 有没有什么办法可以安全而轻松地解决这个简单的问题?GAE实体组/交易

这里是一个代码示例:

Transaction tx = pm.currentTransaction(); 
tx.begin(); 
Product prod = pm.getObjectById(Product.class, "TV"); 
prod.setReserved(true); 
pm.makePersistent(prod); 

Card card = pm.getObjectById(Card.class, "user123"); /// <--- will thorw an exception as card and prod aren't on the same entity group 
card.setProd(prod); 
pm.makePersistent(card); 
try { 
    tx.commit(); 
    break; 
} 
+0

请不要”告诉我,唯一的解决办法是创建一个根'foo'对象,并将其传递给cctor,然后再保存所有卡和产品的数据存储... – bach 2010-04-08 22:06:08

回答