如何使用Objectify .ids()删除一组实体(How to delete a set of Entities using Objectify .ids())

编程入门 行业动态 更新时间:2024-10-28 04:27:33
如何使用Objectify .ids()删除一组实体(How to delete a set of Entities using Objectify .ids())

我正在使用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();

更多推荐

本文发布于:2023-07-21 09:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1209029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   实体   Objectify   Entities   ids

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!