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