1. OpenJPA
  2. OPENJPA-2015

ClassCastException when base entity class has InheritanceType.SINGLE_TABLE base with multiple entity subclasses


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.2, 1.2.3
    • Fix Version/s: 1.2.3
    • Component/s: jpa
    • Labels:


      If multiple entity subclasses extends a entity base class using InheritanceType.SINGLE_TABLE, with mx1 relation from base class to itself, a ClassCastException may occur when the mx1 collection is not empty due to a problem in discriminating the proper entity subclass type.

      Caused by: java.lang.ClassCastException: problem.domain.InputItemRecord
      at problem.domain.InputBatchHeaderRecord.pcReplaceField(
      at org.apache.openjpa.kernel.StateManagerImpl.replaceField(
      at org.apache.openjpa.kernel.StateManagerImpl.storeObjectField(
      at org.apache.openjpa.kernel.StateManagerImpl.storeObject(
      at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.loadEagerJoin(
      at org.apache.openjpa.jdbc.meta.FieldMapping.loadEagerJoin(
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(
      at org.apache.openjpa.kernel.DelegatingStoreManager.initialize(
      at org.apache.openjpa.kernel.ROPStoreManager.initialize(
      at org.apache.openjpa.kernel.BrokerImpl.initialize(
      at org.apache.openjpa.kernel.BrokerImpl.find(
      ... 38 more

      For example:

      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      @DiscriminatorColumn(name = "DISCRIMATOR", discriminatorType = DiscriminatorType.INTEGER)
      public class NachaInputRecord {

      public long identifier;

      @ManyToOne(cascade = CascadeType.MERGE,fetch=FetchType.EAGER)
      @JoinColumn(name = "PARENT_ID")
      private NachaInputRecord parent;

      public class InputItemRecord extends NachaInputRecord {

      public class InputBatchControlRecord extends NachaInputRecord {


        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        6m 20s 1 Albert Lee 09/Jun/11 21:10
        In Progress In Progress Resolved Resolved
        1m 59s 1 Albert Lee 09/Jun/11 21:12
        Resolved Resolved Closed Closed
        215d 23h 33m 1 Albert Lee 11/Jan/12 19:45
        Albert Lee made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Albert Lee made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Albert Lee made changes -
        Field Original Value New Value
        Status Open [ 1 ] In Progress [ 3 ]
        Albert Lee created issue -


          • Assignee:
            Albert Lee
            Albert Lee
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: