Where do I set TransactionOptions with JPA / Google App Engine? [duplicate]

二次信任 提交于 2019-12-11 10:44:23

问题


I use JPA within GAE to persist objects.

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
}

There is a bidirectional Many-To-Many relationship between Event and User. When I insert a new Event and bound it to existing Users inside a transaction, I get the above exception. From the error message I see that I need to tweak TransactionOptions. Where can I set these options?


回答1:


Set the following property in persistence.xml:

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

There is currently no way to enable XG transactions for an individual JDO or JPA transaction. Instead, you specify this for all transactions. [docs]



来源:https://stackoverflow.com/questions/29606651/where-do-i-set-transactionoptions-with-jpa-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!