I'm trying to figure out an issue that I'm seeing. I'm noticing that when I change an entity object definition by adding a new field for instance, sometimes I no longer can get results from previous records that already exist in the datastore. For instance, in this example below, I can see the entity in the datastore, but I'm getting this exception:
SEVERE: No results for query: SELECT FROM com.alero.services.model.MyEntity myEntity WHERE myEntity.key = :key
I'm using JPA with the GAE datastore.
The only way I seem to be able to correct the problem and start getting results again is to delete the appengine-generated directory and then recreate the entities. Is it being cached in some manner and is there something I should be doing to allow the datastore to know that it needs to remove the cache if this is the case?
String queryString = "select from " + MyEntity.class.getName()
+ " myentity where myentity.key = :key";
Key keySub = KeyFactory.createKey("MyEntity", myEntityId);
Query query = em.createQuery(queryString);
query.setParameter("key", KeyFactory.keyToString(keySub));
try {
MyEntity myEntity = (MyEntity) query.getSingleResult();
em.close();
return myEntity;
} catch (Exception e) {
log.severe(e.getMessage());
em.close();
}