Hi,
I have a class hierarchy like this:
@Entity
@Table (name="call_distribution_policies")
@Inheritance (strategy=InheritanceType.JOINED)
public class CallDistributionPolicy implements Serializable, Cloneable{
----------------
}
@Entity
@Table(name="skill_based_call_distribution_policies")
public class SkillBasedCallDistributionPolicy extends CallDistributionPolicy {
--------------
}
public class CallDistributionPolicyDAOJPAImpl extends
AbstractJPADAOImpl<CallDistributionPolicy> implements
CallDistributionPolicyDAO {
}
public CallDistributionPolicy get(long id) {
try {
Query query = entityManager
.createQuery("from CallDistributionPolicy where id = :id");
query.setParameter("id", id);
List<CallDistributionPolicy> resultList = query.getResultList();
if (!CollectionUtils.isEmpty(resultList)) {
return resultList.get(0);
}
return null;
} catch (EntityNotFoundException e) {
return null;
}
}
}
When I do this: log.debug(" loaded: " + callDistributionPolicyDao.get(10).toString())
It prints the toString() of the SkillsBasedCallDistributionPolicy
But when I try to cast it like this:
SkillsBasedCallDistributionPolicy scdp = (SkillsBasedCallDistributionPolicy) callDistributionPolicyDao.get(10)
I get class cast exception.
com.vantage.callcenter.core.entity.acd.CallDistributionPolicy$$EnhancerByCGLIB$$334f3d1b cannot be cast to com.vantage.callcenter.core.entity.acd.SkillBasedCallDistributionPolicy
The instanceof check fails too!
When I inspect the object in eclipse, I see the CGLIB Proxy, but as far as I understand, the CGLIB proxy should extend the SkillsBasedCallDistributionPolicy class? In the CGLIB$CALLBACK_0 property, I can see the entity class is "CallDistributionPolicy" but the target is "SkillsBasedCallDistributionPolicy".
What should be the proper process of loading the Subclass? I can see hibernate is generating all the right SQL and loading the proper subclass, but how can I check the instanceof and cast it into a subclass?
I am using hibernate 3.2.1 , Spring 2.5.5 , cglib2.1_3. Any suggestions?