GAE Entity Groups/Transaction

Posted by bach on Stack Overflow See other posts from Stack Overflow or by bach
Published on 2010-04-08T21:59:09Z Indexed on 2010/04/08 22:03 UTC
Read the original article Hit count: 369

Filed under:

Hi,

Say you have a Client Buying Card object and a product object. When the client chooses the buy opition you create the object and then add a product. It should be transactional but it's not on the same entity group as the product and the card already been persisted, isn't it? Is there any way to overcome this simple scenario safely and easily?

here's a code sample:

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

© Stack Overflow or respective owner

Related posts about google-app-engine