1
我正在构建一个与Google Appengine数据存储集成而不使用JDO的android应用程序。为什么getEntityManager()未定义? “无法解析方法getEntityManager”
我正在尝试构建一个允许我访问数据存储中的数据的端点。我写功能如下,但是,我有一个奇怪的问题,尽管把这个代码到端点的java类...
我得到的是Cannot Resolve Method getEntityManager()
在,我在网上看到的每一个例子中的错误,它都调用这个函数。 - 所以必须有办法让它工作,否则我必须做一些愚蠢的事情。
我错过了什么?我怎样才能解决这个
@Api(name = "getPostsApi", version = "v1", namespace = @ApiNamespace(ownerDomain = "endpoints.myModule.myCo.com",
ownerName = "endpoints.myModule.myCo.com", packagePath=""))
public class GetPostsEndpoint {
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "GetPostsEndpoint")
public CollectionResponse<NewPostBean> listStuff(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<NewPostBean> execute = null;
try {
mgr = getEntityManager(); // <---- Breaks on this line
//Query query = mgr.createQuery("select from Stuff as Stuff");
// limit =1;
//execute = (List<NewPostBean>) query.getResultList();
//cursor = JPACursorHelper.getCursor(execute);
//for (NewPostBean obj : execute)
// ;
//} finally {
// mgr.close();
//}
return CollectionResponse.<NewPostBean>builder().setItems(execute).setNextPageToken(cursorString).build();
}
}
我在网上学习一个教程!我想他们离开了那部分。另外,我添加了一个变量和一个函数来返回EntityManager而不是EntityManagerFactory。非常感谢 – user198923 2014-10-10 22:12:54
非常欢迎:)令人惊讶的教程留下了这样一个重要的部分:P – Patrice 2014-10-10 22:13:35