我在哪里可以使用JDO / Google App Engine设置TransactionOptions? [英] Where do I set TransactionOptions with JDO / Google App Engine?
本文介绍了我在哪里可以使用JDO / Google App Engine设置TransactionOptions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用GAE中的JDO来使用以下方法批量保存对象:
public void makePersistent(PersistenceManager pm,
List< Regeling> makePersistent){
Transaction tx = pm.currentTransaction();
尝试{
//开始交易
tx.begin();
//坚持数据存储
// 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。);
}
//提交事务,将对象刷新到数据存储
tx.commit();
} catch(Exception e){
e.printStackTrace();
} finally {
if(tx.isActive()){
//发生错误以便回滚事务
System.out.println(回滚事务);
tx.rollback();
}
pm.close();
$ / code $ / pre
$ b $ p $:
javax.jdo.JDOUserException:一个或多个实例无法在org.datanucleus.api.jdo.JDOPersistenceManager.makePersistentAll(JDOPersistenceManager。 java:791)
...
at org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582)
NestedThrowablesStackTrace:
java。 lang.IllegalArgumentException:需要显式指定跨组事务,请参阅TransactionOptions.Builder.withXGfound都
元素{
类型:PersistentServiceResultaat $ RegelingInfoLijst $ Regeling
名称: BWBR0001821
}
和
元素{
类型:PersistentServiceResultaat $ RegelingInfoLijst $ Regeling
名称:BWBR0001822
}
所以我尝试设置这些选项:
TransactionOptions ops = TransactionOptions.Builder.withXG(true);
但我找不到一个方法需要 TransactionOptions
对象。在哪里可以设置这些选项?
解决方案将它设置在 jdoconfig.xml中
:
< property name =datanucleus.appengine.datastoreEnableXGTransactionsvalue =true/>
I use JDO within GAE to batch persist objects using the following method:
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();
}
}
This breaks:
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"
}
So I try to set these options:
TransactionOptions ops = TransactionOptions.Builder.withXG(true);
But I can't find a method that takes a TransactionOptions
object. Where can I set these options?
解决方案 Set it in jdoconfig.xml
:
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true" />
这篇关于我在哪里可以使用JDO / Google App Engine设置TransactionOptions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文