我该如何在JDO / Google App Engine中设置TransactionOptions?

6

我在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对象的方法。在哪里可以设置这些选项?


可以解释一下为什么有人给我点了踩吗? - Maarten
1个回答

6

将其设置在jdoconfig.xml中:

<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接