Hi,
Here are code for the entities MyEntity and SubEntity. Is anything
wrong with the code?
/Gunnar
package appengine.test;
import java.io.Serializable;
import java.util.ArrayList;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.persistence.OneToMany;
import com.google.appengine.api.datastore.KeyFactory;
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
= "true")
private String key;
@Persistent
@Element(dependent = "true")
private ArrayList<SubEntity> myList = new ArrayList<SubEntity>();
public Long getId() {
return key == null ? null : KeyFactory.stringToKey(key).getId();
}
public ArrayList<SubEntity> getMyList() {
return myList;
}
public void setMyList(ArrayList<SubEntity> myList) {
this.myList = myList;
}
@Override
public String toString() {
return "MyEntity [keyId=" + getId() + ", myList=" + myList +
"]";
}
public void clearKey() {
key = null;
}
public void add(SubEntity subEntity) {
myList.add(0,subEntity);
}
}
package appengine.test;
import java.io.Serializable;
import javax.jdo.annotations.*;
import com.google.appengine.api.datastore.KeyFactory;
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable="true")
public class SubEntity implements Serializable {
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
= "true")
private String key;
@Persistent
private String name;
public SubEntity(String name) {
super();
this.name = name;
}
public Long getId() {
return key == null ? null : KeyFactory.stringToKey(key).getId();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
// return "SubEntity [name=" + name + ", id=" + getId() + ",
order="
+ getOrdinal() + "]";
return "SubEntity [name=" + name + ", id=" + getId() + "]";
}
public void clearKey() {
key = null;
}
public SubEntity copy() {
SubEntity subEntity = new SubEntity(name);
return subEntity;
}
}
--
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.