asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Intermediate updates of an entity are lost with Objectify 4.0b1 #140

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

What steps will reproduce the problem?
1. The entity 
@Entity
public class User {
    @Id
    String uid;

    @Serialized
    HashMap<String, String> id2val=new HashMap<String, String>();

    int vs;
...
}

2. I repeatedly update the entity (every few seconds)

        try {
          ofy().load().type(User.class).id(action.getUid()).safeGet();
        } catch (NotFoundException e) {

         if(action.isCreateUser()) {
          aqp=new User(action.getUid());
         } else {
           throw new IllegalAccessError("Unknown user: "+action.getUid());
         }
        }

...
            HashMap<String, String> singleVal=new HashMap<String, String>();
            singleVal.put("XXX", ""+cnt);            
            aqp.setVals(singleVal);

            // the value I focus on!!!
            aqp.setVs(aqp.getVs()+1);

            ofy().save().entities(aqp).now();

3.

What is the expected output? What do you see instead?

I only focus on the vs field. The field increments with every call, but then 
sometimes reverts to an earlier state.e.g. vs=1, vs=2, vs=3, vs=4, vs=2!!, etc. 

It looks to me (for what it's worth) as if some kind of caching would come in 
the way.

First I thought I would run into contention problems. It is really scary ;-) 
I'm just glad it works with objectify 3.1.

What version of the product are you using? On what operating system?

Objectify 4.0b1

Please provide any additional information below.

IMPORTANT: the some code works as expected with objectify 3.1.
(i.e. using get/put instead of load/save) 

Original issue reported on code.google.com by robert.h...@gmail.com on 21 Nov 2012 at 2:49

GoogleCodeExporter commented 9 years ago
This is a discussion better had on the objectify google group.  It's hard to 
determine what the problem is from this code, but the issue is almost certainly 
a usage problem.  There are lots of test cases for Objectify that would catch 
something obvious like this.

My first guess is: have you forgotten to install the ObjectifyFilter?  You 
could be getting a stale session cache.

As a side issue, updates should *always* be performed in a transaction.  Just 
because you think something is going to fire at consistent intervals doesn't 
mean it always will.  Updates must be protected by transactions.

If you wish to continue this discussion, please use the Objectify google group.

Original comment by lhori...@gmail.com on 21 Nov 2012 at 4:41

GoogleCodeExporter commented 9 years ago
You are right, it's most likely the ObjectifyFilter. To be honest I didn't 
realize the amount of changes from 3 to 4 and that the documentation for 4 was 
finally out. Really great project btw! 

Many thanks.

Original comment by robert.h...@gmail.com on 21 Nov 2012 at 8:06

GoogleCodeExporter commented 9 years ago
Gonna flag this as invalid - if you find a bug, feel free to open another 
issue.  Thanks.

Original comment by lhori...@gmail.com on 21 Nov 2012 at 8:14