问题
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!
回答1:
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.
回答2:
In a single transaction you can operate entities in the same entity group.
What Can Be Done In a Transaction
来源:https://stackoverflow.com/questions/8251594/how-many-objects-is-too-many-for-in-a-single-transaction-to-googles-datastore