对象不会更新
我有一个以字符串和整数作为字段的对象,我可以毫无问题地更新它。我只是找到具有唯一 id 的正确字段并调用 setPersonalName("Mike");并使用 pm.makePersistent(Personal) 创建这个对象;完成了!
问题出在数组字段上。假设一个人有作业,我将它们存储在
@Persistent
private String[] Assignments;
假设我想更新第三个作业,所以我调用 Personal.setAssignment(3, "Give the report");
和 pm.makePersistent(个人); 这不会以某种方式持久化,并且在日志中没有任何错误(只有这个:org.datanucleus.ObjectManagerImpl close:杰出的非tx更新正在提交到数据存储)!我检查过该值是否在对象中,确实如此。该值已存在于对象 Personal 中。字段没有任何问题,因为字段不是数组。 (顺便说一句,我可以从头开始添加这样的对象,仅更新是行不通的)。
感谢您的任何想法,我整天都在研究,但找不到任何东西......
这是 setAssignment 方法:
public void setAssignment(int AssignmentNo, String Assignment) {
this.Assignments[AssignmentNo-1] = Assignment;
System.out.println(this.Assignments[AssignmentNo-1] + " " + AssignmentNo + " " + this.id);
}
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 say 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 JDO,则多值属性将使用集合存储在数据存储中,如以下链接所述:
http://code.google.com/appengine/docs /java/datastore/jdo/dataclasses.html#Collections
我希望这有帮助!
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!
好的,我找到了解决方案。现在是关于数组的。不知何故,每个更新操作都必须通过一个简单的 setAssignments (String[] Assignments),在其中更新整个数组而不是其中的一个元素。我发现 jdo 以某种方式使用这些方法来更改数据存储中的字段。如果要更改数组中的元素,则必须将“整个”数组更改为
this.Assignments = newAssignments;
而不是this.Assignments[i] = newAssignment;
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 ofthis.Assignments[i] = newAssignment;