2013-10-19 10 views
5

tôi sử dụng JDO trong GAE đến hàng loạt persist các đối tượng sử dụng các phương pháp sau đây:Tôi nên đặt TransactionOptions bằng JDO/Google App Engine ở đâu?

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(); 
    } 
} 

này phá vỡ:

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" 
} 

Vì vậy, tôi cố gắng thiết lập các tùy chọn này:

TransactionOptions ops = TransactionOptions.Builder.withXG(true); 

Nhưng tôi không thể tìm thấy phương thức có đối tượng TransactionOptions. Tôi có thể đặt các tùy chọn này ở đâu?

+0

Chăm sóc để giải thích tại sao một người downvoted? – Maarten

Trả lời

5

Set nó trong jdoconfig.xml:

<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" /> 
Các vấn đề liên quan