Dear Nicholas,

Thank you.

The example code shows the illustration of loading the object outside the
transaction block.  However, sometimes, we send the object to client, and
client modifies the object and sends back to server.  Here, we have to
directly put the object and other processed objects in the transaction
block.

Regards,
Rajesh
*www.VeersoftSolutions.com <http://www.veersoftsolutions.com/>*
*www.GainERP.com <https://www.gainerp.com/>*
*Accounting/Inventory/Orders on Google Cloud Platform and Mobile*


On Wed, Oct 12, 2016 at 4:30 PM, Nicholas Okunew <[email protected]> wrote:

> Objectify requires the Work executed for a transaction to be idempotent.
> When a stale write occurs, the run block is executed again.
>
> In your example, this would happen if there were two concurrent writes on
> the entity that 'tk' points at. If you load inside the transaction, then
> someString will be applied on the most recent write. By loading outside the
> transaction you will overwrite whatever the other concurrent write put in
> the datastore. This is almost always bad.
>
> In this example, you should definitely read inside the transaction.
>
> It can get a bit hairier when you have to write in batches because of XG
> limits and you need, for example, reference data. At that point you're
> making a bit of a tradeoff between correctness, complexity and performance.
>
>
>
> On 12 October 2016 at 20:48, Rajesh Gupta <rajesh.gupta@
> veersoftsolutions.com> wrote:
>
>> Hello All,
>>
>> Is it ok to read the object outside of the transaction block, and then
>> modify and save the object in the transaction block
>>
>> Or, should we always read and write the object with in the transaction
>> block for the transactions to work properly
>>
>>
>>       private void prepare(Key<Trivial> tk) { final Trivial trivNew =
>> ofy().transactionless().load().key(tk).now(); Key<Trivial> k =
>> ofy().transact(new Work<Key<Trivial>>() { @Override public Key<Trivial>
>> run() { trivNew.setSomeString("hellofoo"); return
>> ofy().save().entity(trivNew).now(); } }); }
>> --
>> Regards,
>> Rajesh
>> *www.VeersoftSolutions.com <http://www.VeersoftSolutions.com>*
>> *www.GainERP.com <https://www.gainerp.com>*
>> *Accounting/Inventory/Orders on Google Cloud Platform and Mobile*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "objectify-appengine" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "objectify-appengine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CA%2BS7ijYn_BB2tV4cDuEVUXH3F5uRTOEVauCVaHTxZ_F24PkeLA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to