Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1015481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:24:25+00:00 2026-05-16T10:24:25+00:00

I have a class hierarchy like this: @Entity @Table (name=call_distribution_policies) @Inheritance (strategy=InheritanceType.JOINED) public class

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:24:26+00:00Added an answer on May 16, 2026 at 10:24 am

    I know that this has been a problem in Hibernate during a long time, see for example:

    • ClassCastException cglib lazy loading
    • JPA: instanceof vs. hibernate proxy: when is it safe?
    • How to Avoid ClassCastExceptions when using Hibernate Proxied Objects)

    And by problem, I mean bug, instanceof and casting should just work.

    But I couldn’t reproduce your issue with Hibernate 3.3.0.SP1. Both instanceof and casting to subclasses of a hierarchy using a joined strategy just worked. Tested with:

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-cglib-repack</artifactId>
            <version>2.1_3</version>
        </dependency>
    

    and

        <dependency>
          <groupId>javassist</groupId>
          <artifactId>javassist</artifactId>
          <version>3.8.0.GA</version>
        </dependency>
    

    I’m pretty sure there was a Jira issue for this, but couldn’t find it.


    The problem(bug) is consistent across my application. Can you post your working pom.xml here so I can see exactly what hibernate dependencies are you using?

    Below the dependencies I used:

    <project>
      ...
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.10</version>
          </dependency>
        </dependencies>
      </dependencyManagement>
      ...
      <dependencies>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>3.4.0.GA</version>
          <exclusions>
            <exclusion>
              <groupId>javassist</groupId>
              <artifactId>javassist</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-cglib-repack</artifactId>
          <version>2.1_3</version>
        </dependency>
        ...
      </dependencies>
    </project>
    

    Here is the dependency tree:

    [INFO] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
    [INFO] |  +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
    [INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
    [INFO] |  +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
    [INFO] |  +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
    [INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
    [INFO] |  |  \- commons-collections:commons-collections:jar:3.1:compile
    [INFO] |  +- org.slf4j:slf4j-api:jar:1.5.10:compile
    [INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
    [INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
    [INFO] |  \- javax.transaction:jta:jar:1.1:compile
    ...
    [INFO] \- org.hibernate:hibernate-cglib-repack:jar:2.1_3:compile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A have a class hierarchy that looks somethign like this: class AbstractDataType { public:
I have a class hierarchy that looks like this: class Base<TElement> { public TElement
I have an object hierarchy that looks something like this: public class Book {
I have a class hierarchy like this public abstract class CalendarEventBase{} public class TrainingEvent
I have case where the class hierarchy is something like this, +---------------+ | UIElement
I have a C++ class hierarchy that looks something like this: class A; class
I have a class hierarchy that can be simply put like this: struct Parent
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
I have a class hierarchy similar to this one: public static class BaseConfiguration {
I have a class hierarchy mapped with InheritanceType.JOINED in Hibernate (3.5.6 final) with JPA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.