我正在开发的程序中得到一个 Null ArrayList。出于测试目的,我创建了这个仍然存在相同问题的非常小的示例。我已经尝试过不同的主键,但问题仍然存在。
有什么想法或建议吗?
1-员工类
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@Persistent
private ArrayList<String> nicks;
public Employee(ArrayList<String> nicks) {
this.setNicks(nicks);
}
public String getKey() {
return key;
}
public void setNicks(ArrayList<String> nicks) {
this.nicks = nicks;
}
public ArrayList<String> getNicks() {
return nicks;
}
}
2-员工服务
public class BookServiceImpl extends RemoteServiceServlet implements
EmployeeService {
public void addEmployee(){
ArrayList<String> nicks = new ArrayList<String>();
nicks.add("name1");
nicks.add("name2");
Employee employee = new Employee(nicks);
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(employee);
} finally {
pm.close();
}
}
/**
* @return
* @throws NotLoggedInException
* @gwt.typeArgs <Employee>
*/
public Collection<Employee> getEmployees() {
PersistenceManager pm = getPersistenceManager();
try {
Query q = pm.newQuery("SELECT FROM " + Employee.class.getName());
Collection<Employee> list =
pm.detachCopyAll((Collection<Employee>)q.execute());
return list;
} finally {
pm.close();
}
}
}