我正在使用Objectify从GAE中读取一组实体:
List<CountStore> myList = ofy().load().type(CountStore.class).list();然后我过滤,并删除myList的一些元素。 我现在想要删除剩余列表中的所有ID。 我认为正确的方法是使用.ids():
ofy().delete().type(CountStore.class).ids(myList);但这不起作用 - 它崩溃(见下文),因为它期望myList是Long或String。 任何人都可以建议删除一组实体的最佳方法吗?
谢谢!
java.lang.IllegalArgumentException: id 'com.xyz.abc.CountStore@53d71fff' must be String or Long at com.googlecode.objectify.util.DatastoreUtils.createKey(DatastoreUtils.java:66) at com.googlecode.objectify.util.DatastoreUtils.createKeys(DatastoreUtils.java:112) at com.googlecode.objectify.impl.DeleteTypeImpl.ids(DeleteTypeImpl.java:91) at com.xyz.abc.CounterServlet.doGet(CountrServlet.java:45)...
I'm reading a set of Entities from GAE using Objectify:
List<CountStore> myList = ofy().load().type(CountStore.class).list();I then filter, and remove some of the elements of myList. I now want to delete all the ids in the remaining list. I think the right approach is to use .ids():
ofy().delete().type(CountStore.class).ids(myList);But this doesn't work - it crashes (see below), as it is expecting myList to be a Long or a String. Can anyone advise the best way to delete a set of Entities?
Thanks!
java.lang.IllegalArgumentException: id 'com.xyz.abc.CountStore@53d71fff' must be String or Long at com.googlecode.objectify.util.DatastoreUtils.createKey(DatastoreUtils.java:66) at com.googlecode.objectify.util.DatastoreUtils.createKeys(DatastoreUtils.java:112) at com.googlecode.objectify.impl.DeleteTypeImpl.ids(DeleteTypeImpl.java:91) at com.xyz.abc.CounterServlet.doGet(CountrServlet.java:45)...
最满意答案
感谢您指出只需要一系列长ID。 答案真的很简单,就是创建一个ID的ArrayList,因为我过滤了我要删除的实体:
ArrayList<Long> idList = new ArrayList<Long>(); //Do the Filtering and add IDs to the idList array the delete them all ofy().delete().type(CountStore.class).ids(idList).now();Thanks for pointing out that an array of Long IDs is all that is needed. The answer really was quite simply to create an ArrayList of IDs as I filtered the ones Entities I want to delete:
ArrayList<Long> idList = new ArrayList<Long>(); //Do the Filtering and add IDs to the idList array the delete them all ofy().delete().type(CountStore.class).ids(idList).now();更多推荐
发布评论