拥有关系。丢失参考资料

发布于 2024-10-31 14:04:42 字数 1432 浏览 1 评论 0原文

我有一个包含两个图像的食谱实体:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Recipe {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private MyImage myImage; // full-size image
    @Persistent
    private MyImage thumb; // 224x230 thumbnail version of the above

    public Recipe(Key userKey, String title, Text content, MyImage myImage, MyImage thumb, Set<String> tags) {
        this.userKey = userKey;
        this.title = title;
        this.content = content;
        this.myImage = myImage;
        this.thumb = thumb;
        this.tags = tags;
    }
    public MyImage getMyImage() {
        return myImage;
    }
    public void setMyImage(MyImage myImage) {
        this.myImage = myImage;
    }
    public MyImage getThumb() {
        return thumb;
    }
    public void setThumb(MyImage thumb) {
        this.thumb = thumb;
    }
}

当我将其保存到数据存储时,图像会正确存储。 然而,当我尝试使用引用图像时,问题就出现了 .getMyImage().getThumb()。 它们都指向同一个对象,尽管我可以在 数据存储查看器发现它们是两个不同大小的图像。如果他们 正确存储在数据存储中这意味着存在问题 以及我如何引用我认为的对象。这是为什么呢?

这是我保留的对象,正如您所看到的 myImagethumb 对象是不同的(没有显示它们的代码,但是 相信我,他们是)。

Recipe recipe = new Recipe(user.getKey(), title, new Text(content), myImage, thumb, tagsAsStrings);

有什么想法为什么我继续引用同一个对象吗?

I have a Recipe entity that contains two images:

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Recipe {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private MyImage myImage; // full-size image
    @Persistent
    private MyImage thumb; // 224x230 thumbnail version of the above

    public Recipe(Key userKey, String title, Text content, MyImage myImage, MyImage thumb, Set<String> tags) {
        this.userKey = userKey;
        this.title = title;
        this.content = content;
        this.myImage = myImage;
        this.thumb = thumb;
        this.tags = tags;
    }
    public MyImage getMyImage() {
        return myImage;
    }
    public void setMyImage(MyImage myImage) {
        this.myImage = myImage;
    }
    public MyImage getThumb() {
        return thumb;
    }
    public void setThumb(MyImage thumb) {
        this.thumb = thumb;
    }
}

When I persist this to the datastore, the images are stored correctly.
However the issue comes when I try referencing the images using
.getMyImage() and .getThumb().
They both point to the same object even though I can see in the
datastore viewer that they are two images of different size. If they
are stored in the datastore corretly this means that there's an issue
with how I reference the object I suppose. Why is this?

This is the object I persist, and as you can see the myImage and
thumb objects are different (not showing the code for them, but
trust me they are).

Recipe recipe = new Recipe(user.getKey(), title, new Text(content), myImage, thumb, tagsAsStrings);

Any ideas why I keep on referencing the same object?

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

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

发布评论

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

评论(1

眼泪都笑了 2024-11-07 14:04:42

我意识到我的日志显示“尚不支持此功能。”。遗憾的是,不支持此功能,但我有一个简单的解决方法。

而不是:

@Persistent
private MyImage myImage; // full-size image
@Persistent
private MyImage thumb; // 224x230 thumbnail version of the above

我输入:

private List<MyImage> images; // contains 2 elements
                              // index 0 full-size, 1 is thumbnail (224x230);
                              // since JDO app-engine doesn't support
                              // 2 attributes of the same type

所以基本上是两个图像的列表,而不是两个不同的图像。这有效!

I realized that my logs were showing "This is not yet supported.". It's a pity that this feature is not supported, however I had a simple workaround.

Instead of:

@Persistent
private MyImage myImage; // full-size image
@Persistent
private MyImage thumb; // 224x230 thumbnail version of the above

I put:

private List<MyImage> images; // contains 2 elements
                              // index 0 full-size, 1 is thumbnail (224x230);
                              // since JDO app-engine doesn't support
                              // 2 attributes of the same type

So basically a list of two images instead of two distinct images. This works!

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