8

I have following entity (non-relevant fields/methods are removed).

public class HitsStatsTotalDO
{
    @Id
    transient private Long targetId;

    public Key<HitsStatsTotalDO> createKey()
    {
        return new Key<HitsStatsTotalDO>(HitsStatsTotalDO.class, targetId);
    }
}

So... I'm trying to do batch get for 10 objects for which I construct keys using HitsStatsTotalDO.createKey(). I'm attempting to fetch them in transaction like this:

final List<Key<HitsStatsTotalDO>> keys = ....

// This is being called in transaction..
Map<Key<HitsStatsTotalDO>, HitsStatsTotalDO> result = DAOBase.ofy().get(keys);

which throws following exception:

java.lang.IllegalArgumentException: operating on too many entity groups in a single transaction.

Could you please elaborate how many is too many and how to fix it ? I couldn't find exact number in the documentation.

Thanks!

expert
  • 29,290
  • 30
  • 110
  • 214

2 Answers2

5

The issue is not the number of entities you're retrieving, it's the fact that they're in multiple entity groups. Either do the fetch outside a transaction, or use an XG (Cross Group) transaction.

Lipis
  • 21,388
  • 20
  • 94
  • 121
Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • Yep, I missed that part about 5 entities. – expert Nov 24 '11 at 04:00
  • 1
    At least in the Python SDK 1.7.3, there are two different error messages to the BadRequestError: "cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXG" and "operating on too many entity groups in a single transaction". Your answer solves the former, but the latter can happen in a XG transaction, if it operates on more than 5 entity groups. – Andrey Fedorov Dec 12 '12 at 09:02
  • For XG transactions now, limit appears to be 25 entity groups. See https://cloud.google.com/appengine/docs/standard/java/datastore/transactions?csw=1#What_Can_Be_Done_In_a_Transaction – rimsky Jul 19 '17 at 18:09
1

In a single transaction you can operate entities in the same entity group.

What Can Be Done In a Transaction

88250
  • 76
  • 1
  • 3