Hi Marcin,
On 02/06/2007, at 11:43 AM, Marcin Skladaniec wrote:
I'm having a strange problem. When executing this bit of code:
List categories = aContext.performQuery(new SelectQuery
(Category.class));
if (categories.size() != 0) {
for (int categoriesCount = 0; categoriesCount < categories.size();
categoriesCount++) {
Category cat = (Category) categories.get(categoriesCount);
logger.debug("context equal ? " + cat.getObjectContext().equals
(aContext));
}
}
Try this:
logger.debug("context equal ? " + aContext == cat.getObjectContext());
The spanner in the works here (on the server-side) is the use of the
ObjectContextCallbackInterceptor (see bottom of http://
cayenne.apache.org/doc/lifecycle-callbacks.html) which doesn't
override equals.
Thus, you might also want to try:
if (aContext instanceof ObjectContextCallbackInterceptor)
logger.debug("context equal ? " + ((ObjectContextCallbackInterceptor)
aContext).getContext() == cat.getObjectContext());
else
logger.debug("context equal ? " + aContext == cat.getObjectContext());
(ps, svn up... I've added it to our ObjectContextCallbackInterceptor
subclass ;-) But it'll be worth submitting a bugreport for this.
the contexts are not equal, and I cant find the reason why !
I found this problem, because the perPersist() callback is not
fired when I do
cat.getObjectContext().newObject(SomeEntity.class)
but it is when
aContext.newObject(SomeEntity.class)
to add complexity, postPersist() and other callbacks are fired in
both cases.
with regards,
--
Lachlan Deck