我有一个包含两个图像的配方实体:
@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);
为什么我继续引用相同的对象?
答案 0 :(得分:2)
我意识到我的日志显示“这还不支持。”。遗憾的是,这个功能不受支持,但我有一个简单的解决方法。
而不是:
@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
所以基本上是两个图像的列表而不是两个不同的图像。这有效!