1
votes

Within a transaction, I need to load several entities ( tenths-hundreds ) and those entities were assigned to one parent entity, so they are considered as one entity group ( otherwise we can't load those entities in a single transaction ), which works good, however every time we need to query those entities the parent entity gets loaded

ofy().load().type(clazz).parent(parent).ids(keys);

If we want to load the entities without the parent entity gets loaded then this expected to work and load the entities, but it doesn't

ofy().load().type(clazz).ids(keys);

The reason behind this, if two or more threads do call to load same/different entries ( but same parent ) it would cause too much load on the parent entity " java.util.ConcurrentModificationException: too much contention on these datastore entities. please try again."

Please advice

2

2 Answers

0
votes

The reason for which your ofy().load().type(clazz).ids(keys) doesn't appear to work is that you don't specify the parent key - which is equivalent to looking for keys of root entities (i.e. entities without a parent), which obviously yields a different result.

The parent key (actually the entire ancestry) is embeeded in a child entity key, see Ancestor paths.

So unfortunately you have to specify the parent - the "load" on the parent (actually on the entire entity group, especially at write operations) is the price to pay for the advantages of working within the same entity group.

0
votes

At the root of this question is a fundamental misunderstanding of how transactions and entity groups work in the datastore.

The official documentation is quite accessible:

https://cloud.google.com/appengine/docs/java/datastore/transactions#Java_Entity_groups

I wrote this up some time ago, it may be easier to understand:

https://github.com/objectify/objectify/wiki/Concepts

Keep in mind that this isn't about loading the parent entity. It's about enlisting Entity Groups in a transaction. If you touch any entity in that EG (that is, any entity with a common parent key), you have enlisted the whole EG in the transaction.