如何更改JDO中对象的父对象?

发布于 2024-11-25 11:50:42 字数 560 浏览 1 评论 0原文

我正在使用 JDO 和谷歌应用程序引擎。我有 User 类,它有一个区域对象的 arrayList 。每个区域对象都有一个 Location 对象的数组列表,用于说明坐标。现在我想将一个区域对象从一个用户移动到另一个用户。我正在制作要移动的区域对象的克隆对象,并将其放入其他用户的区域列表中。然后使用remove(index)从第一个用户的列表中删除该区域。但它给出了这个错误:

   Detected attempt to establish User("arash") as the parent of User("mh")/RunData(153) but the entity identified by User("mh")/RunData(153) is already a child of User("mh").  A parent cannot be established or changed once an object has been persisted.

arash 和 mh 是用户,我正在将区域从 mh 移动到 arash。

提前致谢。

我该如何解决这个问题。提前致谢。

I am using JDO and google app engine. I have User class which has an arrayList of area objects. Every area object has an arrayList of Location objects which tells about coordinates. Now i want to move one area object from one user to other. I am making clone object of the area object which i want to move and put that in other user's areaList. And then remove that area from 1st user's list by using remove(index). But its giving this error:

   Detected attempt to establish User("arash") as the parent of User("mh")/RunData(153) but the entity identified by User("mh")/RunData(153) is already a child of User("mh").  A parent cannot be established or changed once an object has been persisted.

Where arash and mh are the users and i am moving area from mh to arash.

Thanks in advance.

How can i solve this problem. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回首观望 2024-12-02 11:50:42

由于您没有提供有关如何编码这些类的信息,因此我无法为您提供任何代码作为灵丹妙药。但可能有!所以这里有一些话:-)

问题是App引擎数据存储区在键或ID(无论你怎么称呼它)中保留对对象父对象的引用。任何好的框架都一样,它会检查你没有做你做过的事情。 :-) 因此这条消息。

当您克隆“区域对象的对象”时,您也克隆了它的 ID 或 Key。正确的?这就是问题所在。您必须为其提供新的密钥或 ID。此时我可以为您提供一些代码,但您提供的信息很少,因此您必须转到 KeyFactory JavaDoc 您自己。

祝你好运!

As you give no information on how you coded those classes the will be no code that I can give you as a silver bullet. But there could be! So here are some words :-)

The issue is that App engine datastore keeps reference to the parent of the object in the key or ID (what ever you call it). And as good any good framework it checks that you do not do something that you did. :-) Hence the message.

When you cloned "object of the area object" you cloned its ID or Key too. Right? That is the problem. You must give it a new Key or ID. This is the point where I could give you some code but you gave little info so you will have to go to the KeyFactory JavaDoc your self.

Good Luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文