假設您有一個客戶購買卡對象和一個產品對象。 當客戶選擇購買選擇時,您創建該對象,然後添加產品。 它應該是事務性的,但它與產品不在同一個實體組中,並且該卡已被保留,不是嗎? 有沒有什麼辦法可以安全而輕鬆地解決這個簡單的問題?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;
}
請不要」告訴我,唯一的解決辦法是創建一個根'foo'對象,並將其傳遞給cctor,然後再保存所有卡和產品的數據存儲... – bach 2010-04-08 22:06:08