1 Reply Latest reply on Dec 12, 2007 3:34 AM by Gerald Quintana

    ClassCastException in Javassist /CGLib

    Gerald Quintana Newbie

      I am following the A to B relationship (many to one) where B is abstract and the relationship lazy, I get a ClassCastException:

      java.lang.ClassCastException: com.mycompany.myproject.MyEntityB_$$_javassist_1
      at com.mycompany.myproject.MyEntityB_$$_javassist_1.getMyEntityB1(EntiteB_$$_javassist_1.java)
      at com.mycompany.myproject.MyServiceImpl.getMyEntityB1FromA(MyServiceImpl.java:68)

      I tried to replace Javassist by CGLib but I got the same:
      java.lang.ClassCastException: com.mycompany.myproject.MyEntityB$$EnhancerByCGLIB$$22ea3be1
      at com.mycompany.myproject.MyEntityB$$EnhancerByCGLIB$$22ea3be1.getMyEntityB1(<generated>)
      at com.mycompany.myproject.MyServiceImpl.getMyEntityB1FromA(MyServiceImpl.java:68)

      Here are my entities:
      @Entity
      public class MyEntityA {
       @Id
       private int id;
       private String name;
       @ManyToOne(fetch=FetchType.LAZY)
       private MyEntityB myEntityB;
       ...
      }
      @Entity
      @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
      public abstract class MyEntityB {
       @Id
       private int id;
       private String name;
       @OneToMany(mappedBy="MyEntityB")
       private List<MyEntityA> myEntitiesA=new ArrayList<MyEntityA>();
       ...
      }
      @Entity
      public class MyEntityB1 extends MyEntityB {
       @OneToMany(mappedBy="myEntityB1")
       private List<MyEntityB2> myEntitiesB2=new ArrayList<MyEntityB2>();
       ...
      }
      @Entity
      public class MyEntityB2 extends MyEntityB {
       @ManyToOne
       private MyEntityB1 myEntityB1;
       ...
      }
      


      Can you tell me where I am wrong?