0
votes

I am using the google datastore with objectify 4.0.1 to store messages. Each message has a list of Comments attached.

Message id 5708313257836544 has 16 comments. At 10:34:08 a 17th comment is added. A GET at 12:01:46 shows the message has 17 comments, another at 12:02 shows it has 16, and the following at 12:04 returns 17 again. No comments have been deleted.

The code is as follows:

@Entity
public class Message  {
    @Id private Long id;

    private List<Comment> comments;
    //getters and setters
  //equals and hashcode over-ridden using id
}



@Embed
public class Comment  {

    private String message;
    private Date date;

    public String getMessage() {
         return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getDate()   {
        return date;
    }

    public int hashCode()   {
        return date.hashCode() * message.hashCode();
    }

    public boolean equals(Object obj)   {
        if (obj==this)
            return true;
        if ( !(obj instanceof Comment) ) 
            return false;
        Comment other = (Comment) obj;
        return other.getMessage().equals(message) && other.getDate().equals(date); 
    }

I've not enabled caching for these objects with the @Cache annotation.

Why might this inconsistency be happening, and how do I prevent it?

1
You haven't shown any of the code which fetches this. If your fetch code is a query, it will show eventual consistency. If it's get-by-key, you're seeing something else - maybe you don't have the ObjectifyFilter installed?stickfigure

1 Answers

2
votes

In short the data is stored with eventual consistency unless you are going to use an ancestor in your entities. This is by design. You can read more about it on Balancing Strong and Eventual Consistency with Google Cloud Datastore.