How can I delete active object entities using the stream api?

Hi,
When I try to delete AO entities that I’ve fetched using ao.stream I get a error:

cannot be cast to net.java.ao.EntityProxyAccessor

The code:

final List categoryCacheEntities = new ArrayList();
ao.stream(CategoryCacheEntity.class, new EntityStreamCallback<CategoryCacheEntity, Integer>()
{
@Override
public void onRowRead(CategoryCacheEntity categoryCacheEntity)
{
categoryCacheEntities.add(categoryCacheEntity);
counter[0]++;
}
});
for(CategoryCacheEntity e : categoryCacheEntities)
{
ao.delete(e);
}

Using ao.find works just fine. Any ideas?

It looks like the entities returned as part of the stream was not intented to be used with ao.delete(). The entities returned in stream() implement a different (interface) type to the ones from the find() method (which does implement the EntityProxyAccessor internface).

I suggest you try using ao.deleteWithSQL() rather than ao.delete(). It will also take up less memory to use deleteWithSQL, since you do not have to keep in memory a list of the entities to be deleted.

1 Like

Thanks, I’ll try the deleteWithSQL solution!