Hello
I have the java.lang.IllegalArgumentException: Invalid Key PB: no
elements for the one to many relation
Here is my parent code
package com.info.shareCar.data.entity;
import java.util.List;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
@PersistenceCapable
public class University {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String university;
@Persistent
private List<GroupInfo> groupList;
@Persistent
private String lowCaseUniversity;
public void setUniversity(String mUniversity) {
this.university = mUniversity;
}
public String getUniversity() {
return university;
}
public void setLowCaseUniversity(String lowCaseUniversity) {
this.lowCaseUniversity = lowCaseUniversity;
}
public String getLowCaseUniversity() {
return lowCaseUniversity;
}
public void setGroupList(List<GroupInfo> groupList) {
this.groupList = groupList;
}
public List<GroupInfo> getGroupList() {
return groupList;
}
public void setKey(Key key) {
this.key = key;
}
public Key getKey() {
return key;
}
}
here is my child code
package com.info.shareCar.data.entity;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
@PersistenceCapable
public class GroupInfo {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String groupName;
@Persistent
private String lowCaseGroupName;
public void setKey(Key key) {
this.key = key;
}
public Key getKey() {
return key;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getGroupName() {
return groupName;
}
public void setLowCaseGroupName(String lowCaseGroupName) {
this.lowCaseGroupName = lowCaseGroupName;
}
public String getLowCaseGroupName() {
return lowCaseGroupName;
}
}
here is the update method
public boolean update(RequestContext aContext) {
Query query = mPm.newQuery(University.class,"lowCaseUniversity
==
Uname");
query.declareParameters("String Uname");
Iterator<University> universityIter =((List<University>)
query.execute(aContext.getUniversity().toLowerCase())).iterator();
while(universityIter.hasNext())
{
University university = universityIter.next();
Iterator<GroupInfo> groupIter =
university.getGroupList().iterator();
while(groupIter.hasNext())
{
if(groupIter.next().getLowCaseGroupName().equals(aContext.getGroup().toLowerCase()))
{
return false;
}
}
GroupInfo group = new GroupInfo();
group.setKey(KeyFactory.stringToKey(aContext.getUniversity().toLowerCase()
+ aContext.getGroup().toLowerCase()));
group.setGroupName(aContext.getGroup());
group.setLowCaseGroupName(aContext.getGroup().toLowerCase());
university.getGroupList().add(group);
mPm.makePersistent(university);
}
return true;
}
both of their primary key are Key object. Thank you
--
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.