Reputation: 3564
I am using a transaction in Objectify 4 to update a bunch of entities, of Kind_A. These have a number of fields I want to modify within the transaction, but also a number of Refs to other entities, e.g.
class Kind_A {
@Id Long id;
@Parent
@Load
Ref<Kind_P> parent;
String name;
@Load
Ref<Kind_B> b;
}
My entity group here is defined by an instance of Kind_P, which will have its own Ref
s, e.g.:
class Kind_P {
@Id Long id;
@Load
Ref<Kind_Q> q;
}
In my transaction, I will ofy().load()
a number of entities as List using an ancestor query, like this:
ofy().load().type(Kind_A.class).ancestor(p).list();
I will then iterate the List, modify, say, the name
field (not the Ref<>
s), then ofy().save()
the List.
All the entities I load()
should have the same @Parent
(p
) since it's an ancestor query.
So, on the face of it, when I load()
and save()
my Kind_A
entities, I am dealing with a single entity group (p
).
However, I am getting an IllegalArgumentException: operating on too many entity groups in a single transaction
. I am guessing this is because Objectify is loading the object graph, including all the Kind_B
s and Kind_Q
s.
Is this correct? So the scope of the transaction is suddenly spreading well beyond the entity group defined by p
.
If so, is there a way to tell Objectify to ignore the @Load annotations inside a transaction?
Is there a way (in, say, the Eclipse debugger) I can find out the entities that are participating in the transaction?
Any insight would be much appreciated!
Upvotes: 0
Views: 433
Reputation: 13556
@Load is oblivious to transactions - the annotation works whether you have a transaction or not. You can control behavior of @Load by using the groupings eg @Load(Sometimes.class) or @Load(unless=Sometimes.class).
If you remove @Load from your @Parent and that solves your problem, it's likely that you have additional @Load annotations in your @Parented class and thus you are transitively pulling in more entities.
Use @Load sparingly and carefully. Note that in Objectify 4.0rc1, you don't even need to use @Load - when you use Ref.get() it will fetch the referenced entity even if it wasn't @Loaded. @Load is just an optimization so that you get efficient fetching into the session cache.
Upvotes: 0