I have found the problem now: You can not have different child
entities of the same type. In my case the thumbnail and fullsize
properties are both of type ImageDataEntity. I think appengine only
uses the type name plus hierarchy information to store the data,
therefore it can not map the entities back to the correct properties.
Does anybody know if this limitation is ever going to be removed?

On Jan 20, 12:20 pm, Torquester <[email protected]>
wrote:
> I have a problem, that Appengine generates duplicate keys and thus my
> objects get overwritten. I have following classes:
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class ProfileEntity  {
>
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     private Key key;
>
>     @Persistent
>     private ImageDescriptionEntity mainImage;
>     ...
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class ImageDescriptionEntity implements Serializable {
>
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     private Key key;
>
>     @Persistent(dependent="true")
>     private ImageDataEntity thumbnail;
>
>     @Persistent(dependent="true")
>     private ImageDataEntity fullsize;
>     ...
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class ImageDataEntity implements Serializable {
>
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>     private Key key;
>
>     @Persistent
>     private Blob data;
>     ...
>
> }
>
> Here's the code I'm using to store the images:
>
> ProfileEntity profile = (ProfileEntity) pm.getObjectById
> (ProfileEntity.class, key);
> ImageDescriptionEntity imageDescription = new ImageDescriptionEntity
> ();
> ImageDataEntity fullsize = new ImageDataEntity();
> imageDescription.setFullsize(fullsize);
> ImageDataEntity thumbnail = new ImageDataEntity();
> imageDescription.setThumbnail(thumbnail);
> profile.setMainImage(imageDescription);
> pm.makePersistent(profile);
> //the problem: fullsize.getKey().equals(thumbnail.getKey())
>
> What happens, is that thumbnail and fullsize get assigned the same key
> from appengine and thus fullsize gets overwritten by the tumbnail.
>
> I'm not sure what I'm doing wrong.
-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to