【发布时间】:2014-05-27 14:27:31
【问题描述】:
我有一个类 Student 和为它生成的 Endpoint 类。 ListStudents 和 insertStudents 方法可以正常工作,但更新和删除不会导致数据存储区发生任何变化。这些方法不会引发任何错误并且调用会返回,但不会进行任何更改。 我的端点代码主要是google插件为eclipse生成的代码:
@ApiMethod(name = "removeStudent", path="remove_student")
public void removeStudent(@Named("email") String email) {
EntityManager mgr = getEntityManager();
try {
Student student = getStudentByEmailName(email);
mgr.remove(student);
} finally {
mgr.close();
}
}
实体管理器getter方法:
private static EntityManager getEntityManager() {
return EMF.get().createEntityManager();
}
@ApiMethod(name = "updateStudent")
public Student updateStudent(Student student) {
EntityManager mgr = getEntityManager();
try {
if (!containsStudent(student)) {
throw new EntityNotFoundException("Object does not exist");
}
mgr.persist(student);
} finally {
mgr.close();
}
return student;
}
还有我的 EMF 课:
public final class EMF {
private static final EntityManagerFactory emfInstance = Persistence
.createEntityManagerFactory("transactions-optional");
private EMF() {
}
public static EntityManagerFactory get() {
return emfInstance;
}
}
使用此端点的客户端是 Android。我只尝试在我的本地服务器上进行测试。 如果我做错了什么,请告诉我。谢谢
【问题讨论】:
标签: java android google-app-engine persistence google-cloud-endpoints