Friday, 15 May 2015

google app engine - How to enable Objectify XA transaction? -



google app engine - How to enable Objectify XA transaction? -

i'm implementing friendship functionality between entities of same type profile. entity kind root (non parent) entity. profile has set<ref<profile>> field named friends , it's getter getfriends().

here code:

public boolean makefriends(final profile profile1, final profile profile2) { final ref<profile> profileref1 = ref.create(profile1); final ref<profile> profileref2 = ref.create(profile2); boolean result = false; // test avoid useless transaction if (!profile1.getfriends().contains(profileref2) && !profile2.getfriends().contains(profileref1)) { // add together friends (set<ref<profile>>) ref of each other result = ofy().transact(new work<boolean>() { @override public boolean run() { profile1.getfriends().add(profileref2); profile2.getfriends().add(profileref1); ofy().save().entities(profile1, profile2).now(); homecoming true; } }); } homecoming result; }

this code give me a:

java.lang.illegalargumentexception: cross-group transaction need explicitly specified, see transactionoptions.builder.withxg

even if objectify documentation says:

objectify requires no special flags enable cross-group transactions. if access more 1 entity grouping in transaction, transaction xg transaction. if access one, not. standard limit of 5 egs applies transactions.

so, why transaction fails?

my code should involve 2 entity groups (one each profile), behind limit of 5. looking @ transactionoptions.builder.withxg documentation, should phone call transactionoptions.builder.withxg(true); before. method returns transactionoptions don't know method pass it!

thanks in advance

objectify turns on xg transactions if environment supports it.

most likely, you're running test case without hrd enabled. must explicitly in localdatastoreservicetestconfig; check local unit testing docs. if getting message in dev instance, create sure check "use hrd" checkbox in eclipse project preferences.

google-app-engine transactions objectify

No comments:

Post a Comment