Objectify's save().entity(E entity).now()
method returns a the Key<E>
of the saved entity
, which is useful when saving a new entity for the first time. So far, so good.
However, it's not entirely clear what this method returns when saving an entity that was already present in datastore, or whether the return value can tell me anything about whether that write was successful. Can I assume it was successful unless a RuntimeException
is thrown, as per these javadocs? If so, is the true regardless of whether the write is inside a transaction?
Specifically, I'm reading, then modifying and saving two entities in an XG transaction using Objectify. I'm currently checking the return value of the first save before saving the second, like this:
if(ofy().save().entity(entA).now() != null) {
ofy().save().entity(entB).now();
}
Firstly, I guess the first thing is I should save these with one ofy().save().entities(ent1, ent2).now()
call?
Secondly, is it even meaningful for me to check the return value of the ofy().save().entity().now()
call:
- ever
- inside a transaction? (e.g., Objectify retries if it catches a
ConcurrentModificationException
but what happens if a transaction commit keeps failing?)
Thanks for any clarification anyone can give on this.