0 Replies Latest reply on Oct 11, 2007 4:51 PM by Georges Berscheid

    Hibernate proxy class problem

    Georges Berscheid Newbie


      I'm having the following odd situation:

      @Inheritance(strategy = InheritanceType.JOINED)
      public abstract class Customer { @Id private int id; }
      public class SomeCustomer extends Customer { private String name; }

      I'm using Entity Manager to retrieve entities by their primary key:
      entityManager.find(Customer.class, 5);

      The primary key 5 belongs to a SomeCustomer entity. It's in the id field of both Customer and SomeCustomer tables (due to join inheritance). However, the query returns an object that has the type Customer_$$_javassist_16 that cannot be cast to SomeCustomer (ClassCastException).
      However, if I execute the following query:
      entityManager.find(SomeCustomer.class, 5);

      I will see a warning in my logfile: ProxyWarnLog: Narrowing proxy to class SomeCustomer - this operation breaks ==
      Subsequent call to the first find() query will now also return the right object of the right type.

      Does anybody know what's going on here or how I can manually narrow down my proxy object to what I want to have if it fails?

      Thanks a lot,