开发者

Object won't update

开发者 https://www.devze.com 2023-03-31 20:37 出处:网络
I have an object with strings and integers as fields, which I can update without a problem. I just find the correct field with the unique id and call setPersonalName(\"Mike\"); and make this object wi

I have an object with strings and integers as fields, which I can update without a problem. I just find the correct field with the unique id and call setPersonalName("Mike"); and make this object with pm.makePersistent(Personal); And it is done!

The problem is with the array fields. Let's say a personal has assignments and I store these in

@Persistent
private String[] Assignments;    

Let's s开发者_Go百科ay I want to update the 3rd assignment so I call Personal.setAssignment(3, "Give the report");

and pm.makePersistent(Personal); This wont be made persistent somehow and in logs there aren't any errors (only this: org.datanucleus.ObjectManagerImpl close: Outstanding nontx update being committed to datastore)! I have checked whether the value is in the object, it is. The value is already in the object Personal. There aren't any problems with fields, which are not an array. (By the way I can add an object like this from scratch only updating won't work).

Thanks for any idea, I was researching all day long, but couldn't find anything...

here is setAssignment method:

    public void setAssignment(int AssignmentNo, String Assignment) {
    this.Assignments[AssignmentNo-1] = Assignment;
    System.out.println(this.Assignments[AssignmentNo-1] + "       " + AssignmentNo + "     " + this.id);
}


If you are using JDO, then multi-valued properties are stored in the datastore using Collections as described in the following link: http://code.google.com/appengine/docs/java/datastore/jdo/dataclasses.html#Collections

I hope this helps!


Ok I have found the solution. It is now about the array. Somehow each update operation has to be through a simple setAssignments (String[] Assignments), where you update entire array instead of one element in it. Somewhere I have found that jdo is somehow using these methods to change the field in datastore. If you want to change an element in an array you have to change "entire" array as this.Assignments = newAssignments; instead of this.Assignments[i] = newAssignment;

0

精彩评论

暂无评论...
验证码 换一张
取 消