I thought I would add some further information. I am using ObjectDB 2.2.8 and Java 1.6. I am making an EclipseRCP project that records athletic/swimming, etc results. The core of the projects works as expected. The problem is in a plugin I am making for the project to do team scoring. (I expect I will have similar problems in other plugins I have in mind)
To hopefully make it clearer, the following method is where there exception occurs:
public SSVXCObjectParcel load() throws GenderException, StorageFailedToConnectException, StorageMissingTypeException{
cop = new SSVXCObjectParcel();
cop.addListener(this);
this.addListener(cop);
List<XCCompetitorCount> list = ((IStorageDb)parent_storage).getEntityManager().createQuery("select e from XCCompetitorCount e", XCCompetitorCount.class).getResultList();
for(XCCompetitorCount ico : list){
cop.add(ico);
}
this.loaded = true;
return cop;
}
When the query is run, debugging shows that "list" contains the XCCompetitorCount objects I persisted earlier. The method fails in the line in bold, ie at the start of the for loop. If however, I change the method to look like:
List<XCCompetitorCount> list = ((IStorageDb)parent_storage).getEntityManager().createQuery("select e from XCCompetitorCount e", XCCompetitorCount.class).getResultList();
for(ICoreObject ico : list){
cop.add(ico);
}
then debugging moves past that line and fails in the cop.add() method at the line if(obj instanceof XCCompetitorCount){. ICoreObject is the interface that is implemented by all the persisted objects. Yet the TypedQuery should be returning XCCompetitorCount objects! The add() method is below with the alternate problem in bold
public void add(ICoreObject obj, boolean fireEvent) {
if (obj == null) {
ErrorHandler.error("Trying to add null object to Shield COP. Ignoring...");
return;
}
if (obj instanceof XCCompetitorCount) {
if (!this.XCCompetitorCounts.contains(obj)) {
this.XCCompetitorCounts.add((XCCompetitorCount) obj);
}
}
else{
ErrorHandler.error("Error trying to add object of unknown class "+obj.getClass().toString());
}
if (fireEvent) this.updateChanged(obj);
}
So it seems that the query is returning XCCompetitorCount objects that are not being recognised as XCCompetitorCount objects. I cannot figure out why.