拥有关系。丢失参考资料
我有一个包含两个图像的食谱实体:
@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()
。 它们都指向同一个对象,尽管我可以在 数据存储查看器发现它们是两个不同大小的图像。如果他们 正确存储在数据存储中这意味着存在问题 以及我如何引用我认为的对象。这是为什么呢?
这是我保留的对象,正如您所看到的 myImage
和 thumb
对象是不同的(没有显示它们的代码,但是 相信我,他们是)。
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
andthumb
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到我的日志显示“尚不支持此功能。”。遗憾的是,不支持此功能,但我有一个简单的解决方法。
而不是:
我输入:
所以基本上是两个图像的列表,而不是两个不同的图像。这有效!
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:
I put:
So basically a list of two images instead of two distinct images. This works!