2
我有一个包含两个图像配方实体:拥有的关系。失去参考
@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);
任何想法,为什么我一直在引用同一个对象?
请问您可以发布getMyImage()和getThumb()的代码吗? – 2011-04-10 19:49:22
@Riley:添加了代码 – 2011-04-10 21:37:00
+1来扼杀我。如果你不能很快得到比我更了解的人的帮助,请发布一个小问题来证明问题。 FWIW,这是我在某处犯了一个粗心的错误时遇到的问题 - 我唯一的建议是检查代码,以使您认为您再次获得相同的对象。祝你好运! – 2011-04-10 22:12:08