Where do I set TransactionOptions with JPA / Googl

2019-07-26 04:58发布

This question already has an answer here:

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条回答
Ridiculous、
2楼-- · 2019-07-26 05:13

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]

查看更多
登录 后发表回答