在哪里使用 JDO/Google App Engine 设置 TransactionOptions?
Posted
技术标签:
【中文标题】在哪里使用 JDO/Google App Engine 设置 TransactionOptions?【英文标题】:Where do I set TransactionOptions with JDO / Google App Engine? 【发布时间】:2013-10-28 03:50:05 【问题描述】:我在 GAE 中使用 JDO 使用以下方法批量持久化对象:
public void makePersistent(PersistenceManager pm,
List<Regeling> makePersistent)
Transaction tx = pm.currentTransaction();
try
// Start the transaction
tx.begin();
// Persist to the datastore
// pm.makePersistentAll(makePersistent);
for (int i = 0; i < makePersistent.size(); i += BATCH_SIZE)
int last = i + BATCH_SIZE;
last = last > makePersistent.size() ? makePersistent.size()
: last;
pm.makePersistentAll(makePersistent.subList(i, last));
pm.flush();
System.out.println("Made "+last+" items persistent.");
// Commit the transaction, flushing the object to the datastore
tx.commit();
catch (Exception e)
e.printStackTrace();
finally
if (tx.isActive())
// Error occurred so rollback the transaction
System.out.println("Rolling back transaction");
tx.rollback();
pm.close();
这会中断:
javax.jdo.JDOUserException: One or more instances could not be made persistent
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistentAll(JDOPersistenceManager.java:791)
...
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
NestedThrowablesStackTrace:
java.lang.IllegalArgumentException: cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXGfound both
Element
type: "PersistentServiceResultaat$RegelingInfoLijst$Regeling"
name: "BWBR0001821"
and
Element
type: "PersistentServiceResultaat$RegelingInfoLijst$Regeling"
name: "BWBR0001822"
所以我尝试设置这些选项:
TransactionOptions ops = TransactionOptions.Builder.withXG(true);
但我找不到采用TransactionOptions
对象的方法。我可以在哪里设置这些选项?
【问题讨论】:
想解释一下为什么有人投了反对票? 【参考方案1】:设置在jdoconfig.xml
:
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" />
【讨论】:
以上是关于在哪里使用 JDO/Google App Engine 设置 TransactionOptions?的主要内容,如果未能解决你的问题,请参考以下文章
“ app:layout_constraintHorizo ntal_bias是什么意思,它在哪里使用?
Mac App Store 的多语言应用程序 - 在哪里设置 Mac App Store 中显示的语言?