This is a current limitation that I hope to get rid of fairly soon. The problem is that the parent does not have the key of the child as a field. Instead, in order to find the child, the parent issues an ancestor query to find the single object of the appropriate type that is a direct descendant. I describe the reason for this odd implementation in detail in my Google IO talk <http://www.youtube.com/watch?v=2jW2iSKDipY> from last summer. An annoying side effect of this implementation is that you can't have two relationship fields of the same type because we have no way of knowing which child is associated with which field. We'll get it straightened out in the next few releases, I promise.
Max On Wed, Oct 28, 2009 at 9:49 PM, lent <[email protected]> wrote: > > Hello, > > I'm using JPA with SDK 1.2.5 and I'm having a problem with multiple > owned One To One relationships where the relationships are to the same > type. The code is as below and Contributor class has three owned One > to One relationships to ContentValue. > > What I'm finding is that when I set one of the One to One properties > in one transaction (e.g. picutre) in one request and then later on in > a different request and transaction I retrieve another of the One to > One properties (e.g. tagData), I get back the ContentValue I set for > the first property (picture). > > I'm doing the following to set the property: > > Contributor contributor = <load contributor here>; > ContentValue picture = contributor.getPicture(); > if ( picture == null ) { > picture = new ContentValue(); > contributor.setPicture( picture ); > pictureContent.setContentValueType( ContentValueType.PICTURE ); > } > ... > > > If anyone knows why I'm having this problem, please let me know. > > Regards, > Len > > > Contributor.java > ---------------- > > package abc; > > //import com.google.appengine.api.datastore.Key; > //import com.google.appengine.api.datastore.KeyFactory; > import org.datanucleus.jpa.annotations.Extension; > > import javax.persistence.AttributeOverrides; > import javax.persistence.CascadeType; > import javax.persistence.Embedded; > import javax.persistence.FetchType; > import javax.persistence.Entity; > import javax.persistence.Enumerated; > import javax.persistence.GeneratedValue; > import javax.persistence.GenerationType; > import javax.persistence.Id; > import javax.persistence.OneToMany; > import javax.persistence.OneToOne; > import javax.persistence.Transient; > > import java.util.ArrayList; > import java.util.Date; > import java.util.List; > import java.util.Date; > > @Entity > public class Contributor { > @Id > @GeneratedValue(strategy=GenerationType.IDENTITY) > @Extension(vendorName="datanucleus", key="gae.encoded-pk", > value="true") > private String id; > > @Enumerated > private String firstName; > > @Enumerated > private String lastName; > > @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY ) > private ContentValue picture; > > @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY ) > private ContentValue thumbnailPicture; > > @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY ) > private ContentValue tagData; > > public void setId(String id) { > this.id = id; > } > > public String getId() { > return id; > } > > public void setFirstName(String firstName) { > this.firstName = firstName; > } > > public String getFirstName() { > return firstName; > } > > public void setLastName(String lastName) { > this.lastName = lastName; > } > > public String getLastName() { > return lastName; > } > > public void setPicture(ContentValue picture) { > this.picture = picture; > } > > public ContentValue getPicture() { > return picture; > } > > public void setThumbnailPicture(ContentValue thumbnailPicture) { > this.thumbnailPicture = thumbnailPicture; > } > > public ContentValue getThumbnailPicture() { > return thumbnailPicture; > } > > public void setTagData(ContentValue tagData) { > this.tagData = tagData; > } > > public ContentValue getTagData() { > return tagData; > } > > } > > > ContentValue.java > ----------------- > package abc; > > import org.datanucleus.jpa.annotations.Extension; > > import com.google.appengine.api.datastore.Blob; > > import javax.persistence.AttributeOverrides; > import javax.persistence.Entity; > import javax.persistence.CascadeType; > import javax.persistence.Enumerated; > import javax.persistence.Embedded; > import javax.persistence.GeneratedValue; > import javax.persistence.GenerationType; > import javax.persistence.Id; > import javax.persistence.NamedQuery; > import javax.persistence.OneToOne; > > @Entity > public class ContentValue { > @Id > @GeneratedValue(strategy=GenerationType.IDENTITY) > @Extension(vendorName="datanucleus", key="gae.encoded-pk", > value="true") > private String id; > > @Enumerated > @Extension(vendorName="datanucleus", key="gae.parent-pk", > value="true") > private String parentId; > > @Enumerated > private ContentValueType contentValueType; > > @Enumerated > private Blob content; > > @Enumerated > private String contentType; > > public void setId(String id) { > this.id = id; > } > > public String getId() { > return id; > } > > public void setParentId(String parentId) { > this.parentId = parentId; > } > > public String getParentId() { > return parentId; > } > > public void setContentValueType(ContentValueType contentValueType) { > this.contentValueType = contentValueType; > } > > public ContentValueType getContentValueType() { > return contentValueType; > } > > public void setContent(Blob content) { > this.content = content; > } > > public Blob getContent() { > return content; > } > > public void setContentType(String contentType) { > this.contentType = contentType; > } > > public String getContentType() { > return contentType; > } > } > > > ContentValueType.java > --------------------- > import java.io.Serializable; > > package abc; > > public enum ContentValueType implements Serializable { > PICTURE, // content is a picture > THUMBNAIL, // content is a thumbnail > TAG_DATA // tag data > } > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
