I'm trying to write to a JDO store using this code:
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.currentTransaction().begin();
// deactivate all for current domain
Query q = pm.newQuery(CampaignStore.class, "domain == '" + domain +"'");
Collection result = (Collection) q.execute();
CampaignStore toBeEdited = null;
Iterator iter = result.iterator();
while (iter.hasNext()) {
toBeEdited = (CampaignStore) iter.next();
toBeEdited.setActive(false);
}
result.clear();
// set new one active
q = pm.newQuery(CampaignStore.class, "id == " + id);
result = (Collection) q.execute();
toBeEdited = (CampaignStore) result.iterator().next();
if (toBeEdited == null) {
LOG.log(Level.WARNING, "setActiveCampaign: Unable to find Campaign ID '"+ id +"'");
pm.currentTransaction().rollback();
return;
}
toBeEdited.setActive(true);
pm.currentTransaction().commit();
LOG.log(Level.INFO, "setActiveCampaign: Active Campaign ID is now '"+ id +"'");
}
catch (Exception e) {
pm.currentTransaction().rollback();
LOG.log(Level.WARNING, "setActiveCampaign: Exception: "+ e.getMessage());
} finally {
pm.close();
}
Unfortunately I get an "Query result sets are not modifiable" exception.
I'm quite sure it comes from the first query with the iteration, cause the second one alone will work.
Any ideas what I need to change to make the query result modifiable?