Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GAE实体组/交易_Java_Google App Engine_Transactions - Fatal编程技术网

Java GAE实体组/交易

Java GAE实体组/交易,java,google-app-engine,transactions,Java,Google App Engine,Transactions,假设您有一个客户购买卡对象和一个产品对象。 当客户选择购买观点时,您创建对象,然后添加产品。 它应该是事务性的,但它与产品不在同一个实体组中,并且卡已经被持久化了,不是吗? 有什么方法可以安全轻松地克服这个简单的情况吗 下面是一个代码示例: Transaction tx = pm.currentTransaction(); tx.begin(); Product prod = pm.getObjectById(Product.class, "TV"); prod.setReserved(true

假设您有一个客户购买卡对象和一个产品对象。 当客户选择购买观点时,您创建对象,然后添加产品。 它应该是事务性的,但它与产品不在同一个实体组中,并且卡已经被持久化了,不是吗? 有什么方法可以安全轻松地克服这个简单的情况吗

下面是一个代码示例:

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;
}
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”);// 这篇博文可能会有帮助:


(尽管示例是Python,但概念完全相同)

请不要告诉我,唯一的解决方案是创建一个根“foo”对象,并将其传递给cctor,然后再持久化到所有卡和产品的数据存储中……您在6个多月前就到了那里!)