[英]Update query in DataStore of google app engine - java
I am newbie to app engine. 我是App Engine的新手。 I want to update some fields of my entity in datastore. 我想更新数据存储区中实体的某些字段。 For that i have created query
like below but neither it updates my entity nor throws error. 为此,我创建了如下query
,但它既不会更新我的实体也不会引发错误。 I don't know where i am going wrong.I referred this SO post but i have huge collection of data. 我不知道我要去哪里错。我提到了这篇文章,但我收集了大量数据。 Therefor, for me, its very hard to fetch hundreds of records and persist them.Please help me to solve this problem. 因此,对我来说,很难获取数百条记录并保留它们。请帮助我解决此问题。
Code: 码:
@ApiMethod(name = "updateUserProfile", httpMethod = HttpMethod.GET, path = "userfeedmasterendpoint/updateProfile")
public void updateUserProfile(@Named("userName") String uName,
@Named("uAbout") String userAbout)
{
EntityManager mgr = null;
try {
mgr = getEntityManager();
Query query = mgr
.createQuery("update UserFeedMaster u set u.userAbout = :uAbout where u.userName=:userName");
query.setParameter("userName", uName);
query.setParameter("uAbout", userAbout);
query.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
return;
}
A query will only ask the datastore for a set of object satisfying a criteria and retrieve these. 查询将仅向数据存储区询问一组满足条件的对象,然后检索这些对象。 To update an object you need to retrieve it (with a query for instance), update this object and then put it back in the datastore (by calling your ORM put method). 要更新对象,您需要检索它(例如,使用查询),请更新该对象,然后将其放回数据存储中(通过调用ORM put方法)。
If you are new to AppEngine and you want to use the datastore in an easy way, you should look at Objectify. 如果您不熟悉AppEngine,并且想以简单的方式使用数据存储,则应查看Objectify。 It is a java ORM for the Datastore. 它是数据存储区的Java ORM。 Here is a short description of the project : 这是该项目的简短说明:
Objectify is a Java data access API specifically designed for the Google App Engine datastore. Objectify是专门为Google App Engine数据存储区设计的Java数据访问API。 It occupies a "middle ground"; 它占据了“中间地带”。 easier to use and more transparent than JDO or JPA, but significantly more convenient than the Low-Level API. 与JDO或JPA相比,它更易于使用且更加透明,但比Low-Level API更加方便。 Objectify is designed to make novices immediately productive yet also expose the full power of the GAE datastore. Objectify旨在使新手立即提高工作效率,同时也展现GAE数据存储的全部功能。
https://code.google.com/p/objectify-appengine/ https://code.google.com/p/objectify-appengine/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.