This question already has an answer here:
Where do I set TransactionOptions with JDO / Google App Engine?
                                
                                    (1个答案)
                                
                        
                                4年前关闭。
            
                    
我在GAE中使用JPA来持久化对象。

javax.persistence.PersistenceException: Illegal argument
    at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:298)
    at org.datanucleus.api.jpa.JPAEntityTransaction.commit(JPAEntityTransaction.java:122)
Caused by: java.lang.IllegalArgumentException: cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXGfound both
Element {
  type: "Event"
  id: 0x11000000000000
}
and Element {
  type: "User"
  id: 0x14000000000000
}


事件和用户之间存在双向的多对多关系。当我插入一个新的Event并将其绑定到事务中的现有用户时,会出现上述异常。
从错误消息中,我看到我需要调整TransactionOptions。在哪里可以设置这些选项?

最佳答案

persistence.xml中设置以下属性:

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


当前无法为单个JDO或JPA事务启用XG事务。而是为所有事务指定此名称。 [docs]

10-08 09:27