I have a query which returns a list of entities. When I try to put this list to the cache, I get the familiar java.lang.IllegalArgumentException
.
However... I can put every item inside the list to the cache with no problems. Even when I create a new LinkedList
, copy entities from the fetched list to this new one using for cycle and try to put it to the cache, it also works.
List<MyEntity> a = (List<MyEntity>) q.execute(getKey());
List<MyEntity> b = new LinkedList<MyEntity>();
for (MyEntity e : a)
b.add(e);
cache.put(key, b); // this works
cache.put(key, a); // this doesn't
So what I am missing? Caching other queries works, I don't know why this one is differen.
Most probably
List
returned by JDO query is not serializable, because it's a dynamic proxy.To make a copy you can simply use
Note: this makes a new list
a
from elements ofb
, but is does not make a copy of elements, so it's pretty lightweight.