GAE实体组/交易

时间:2010-04-08 21:59:09

标签: java google-app-engine transactions

假设您有一个客户购买卡对象和一个产品对象。 当客户选择购买选择时,您创建对象,然后添加产品。 它应该是事务性的,但它与产品不在同一个实体组中,并且卡已经被保留,不是吗? 有没有办法安全轻松地克服这个简单的场景?

这是一个代码示例:

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

1 个答案:

答案 0 :(得分:1)

此博客文章可能会有所帮助:http://blog.notdot.net/2009/9/Distributed-Transactions-on-App-Engine

(尽管这些例子都是在Python中,但概念完全相同)

相关问题