Search code examples
javagwtgoogle-cloud-datastorerequestfactoryobjectify

Can update field only once in GAE Datastore using Objectify


I am serializing Diagram class to GAE Datastore using Objectify. I can update (serialize) all the fields as many times as I want, except Integer arrowTypeId, that is only updated once, and after that keeps always the same value. If I leave the app and run it again, I can update again that value, but only once.

To update arroyTypeId I am calling sendDatabaseUpdateDiagramArrows(). This is what happens:

  1. I call sendDatabaseUpdateDiagramArrows() with value 1
  2. I set that value to the DiagramProxy.setArrowTypeId().
  3. As a test, I change the diagram title to DiagramProxy.getArrowTypeId()
  4. I call save()
  5. On the DAO save(), the wrong value of ArrowTypeId is received (keeps the old one), but surprisingly, the Title has the right ArrowTypeId stored from step 3)
  6. Changes are serialized with this problem. No exceptions are displayed.

    • Note that I am able to update ArrowTypeId value the first time, from default value 1 to 2. Buth the next time keeps always value 2.
    • Edit: If I change arrowTypeId to a String, I have the same issue.

DatabaseUtils.java

public static DiagramProxy sendDatabaseUpdateDiagramArrows(DialectiveRequestFactory requestFactory, Integer value, DiagramProxy cellDiagramProxy)
{
    DiagramRequest diagramRequest = requestFactory.diagramRequest();
    DiagramProxy newDiagramProxy = diagramRequest.edit(cellDiagramProxy);
    Date date = new Date();

    newDiagramProxy.setArrowTypeId(value);
    newDiagramProxy.setTitle(Integer.toString(newDiagramProxy.getArrowTypeId()));
    diagramRequest.save(newDiagramProxy).fire();

    return cellDiagramProxy;
}

Diagram.java

@Entity
public class Diagram extends DatastoreObject{


@Indexed private String diagramId;
    private String title;
    private Integer arrowTypeId;

    public String get_id() {
        return diagramId;
    }
    public void set_id(String diagramId) {
        this.diagramId = diagramId;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public Integer getArrowTypeId() {
        return arrowTypeId;
    }
    public void setArrowTypeId(Integer arrowTypeId) {
        this.arrowTypeId = arrowTypeId;
    }
}

DiagramProxy.java

@ProxyFor(value = Diagram.class, locator = ObjectifyLocator.class)
public interface DiagramProxy extends EntityProxy{
    void set_id(String id);
    void setTitle(String title);
    void setArrowTypeId(Integer arrowTypeId);
    Integer getArrowTypeId();
    String get_id();
    String getTitle();
}

DiagramDao.java

public class DiagramDao extends ObjectifyDao<Diagram>{

    public void save(Diagram diagram)
    {
        this.put(diagram);
    } }

Solution

  • Let me guess :) as I don't have experience with GAE datastore.

    I don't get the point, why you make

    @Indexed private String diagramId;
    

    but getter and setter with non-standard names:

    public String get_id() {
        return diagramId;
    }
    public void set_id(String diagramId) {
        this.diagramId = diagramId;
    }
    

    I'd rather go for:

    @Indexed private String diagramId;
    public String getDiagramId() {
            return diagramId;
        }
        public void setDiagramId(String diagramId) {
            this.diagramId = diagramId;
        }
    

    One more thing is that DiagramRequest code has not been published, maybe that could help in seeing the problem.