Sunday, January 15, 2012

Cannot read fields from a deleted object

The above error was causing me some grief, I did delete the object but for some reason a populate query was picking it up from the datastore.

I was able to check if the object was deleted with the following JDOHelper function: JDOHelper.isDeleted(item)

I used it as follows:

import javax.jdo.JDOHelper;
import javax.jdo.ObjectState;

public List getWatchList() {
List watchList = new ArrayList();
List result = ccs.myasxpager.datasource.WatchList.getWatchList();

for (ccs.myasxpager.persistence.schema.WatchList item : result) {
if (JDOHelper.isDeleted(item))
String[] watchListItem = {item.getAsxCode(), ccs.myasxpager.datasource.Company.getCompanyNameByCode(item.getAsxCode()), ccs.myasxpager.datasource.Company.getIndustryByCode(item.getAsxCode())};
return watchList;

No comments: