One more thing to add - This is using the PB API. I changed to using
PB for getting objects by ID as it seemed to perform much better than ODMG.
If i swap the code that retrieves all objects by ID:
PersistenceBroker broker = ((HasBroker) tx).getBroker();
Criteria criteria = new Criteria();
criteria.addEqualTo("id", new Integer(itemId));
QueryByCriteria query =new QueryByCriteria(Class.forName(itemType),
criteria);
Object o = broker.getObjectByQuery(query);
With the previous ODMG code:
String queryStr = "select obj from " + itemType + " where id=$1";
OQLQuery query = odmg.newOQLQuery();
query.create(queryStr);
query.bind(Integer.toString(itemId));
List objects = (List) query.execute();
return objects.get(0);
And enable proxying then it works fine. BUT at a SIGNIFICANT preformance
loss.
----- Original Message -----
From: "Daniel Perry" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, January 06, 2004 12:00 PM
Subject: classcast exception (proxy problem)
I've got a problem where an object has a 1:1 relationship with the supertype
of another object. If i proxy the relationship, then i cannot cast the
related object to it's actual type. (it throws a ClassCastException).
The code below is part of Review. Review Implements the interface IReview.
IReview extends the interface IMeeting. IReview has a method
getPreviousMeting() which returns an IMeeting (this is proxied in the
repository.xml). This IMeeting is an Meeting or a Review. IMeeting has a
method getType() which gives an integer denoting it's type.
What i think is happening is the previousMeeting is being retrieved and
proxied as implementing IMeeting, but it is an Review, and as such should
implement IReview. Setting proxy=false fixes the problem.
public List getPreviousMeetings() {
try {
ArrayList previousList = new ArrayList();
IMeeting m = this;
while (m.getType() == Meeting.REVIEW) {
m = ((IReview) m).getPreviousMeeting();
previousList.add(m);
}
return previousList;
} catch (Exception ex) {
ex.printStackTrace();
return new ArrayList();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]