2013-10-19 43 views
5

我使用JDO內GAE批量堅持使用下面的方法對象:我可以在哪裏設置TransactionOptions與JDO/Google App Engine?

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對象的方法。我可以在哪裏設置這些選項?

+0

護理解釋爲什麼有人downvoted? – Maarten

回答

5

設置它jdoconfig.xml

<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" /> 
相關問題