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?
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!