Suppose I have a base class, Cat, and two derived classes: DomesticCat and WildCat. I define proxy interfaces to these persistent classes in order to use lazy initialization: ICat, IDomesticCat and IWildCat.
Now when I query the base class, how can I find the most-derived class of the returned object?
Code:
Query q = session.createQuery("from Cat");
Iterator it = q.list().iterator();
while (it.hasNext()) {
ICat cat = (ICat)it.next();
if (cat instanceof IWildCat)
// This is true for all objects !!!!!
if (cat instanceof IDomesticCat)
// This is true for all objects !!!!!
}
Apparently instanceof doesn't work on proxy interfaces. Is there an alternative? Am I doing something wrong?
Thanks in advance,
Raph