1 Reply Latest reply on May 22, 2013 4:43 PM by Cdelahun-Oracle

    Different behavior with TLG with inheritance based entity

    S. Saravanan-Oracle
      I've 2 single table inheritance based entities as shown below (both the entities are coherence intercepted):

      @Table(name = "EMPLOYEE")
      @DiscriminatorColumn(name = "SUBTYPE", discriminatorType = DiscriminatorType.STRING, length = 4)
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      @CacheInterceptor(value = CoherenceInterceptor.class)
      public class Employee {
      private Long id;
      private String name;
      private String subtype;

      @CacheInterceptor(value = CoherenceInterceptor.class)
      public class Manager extends Employee {

      When I explicitly set the discriminator column (subtype in this case), the subtype I set was ignored and the assigned discriminator value is persisted in the DB. But in the Grid, a different subtype than the one persisted in the DB is pushed.

      EntityManager em = emf.createEntityManager();
      Employee employee = new Employee();
      employee.setName("some name");
      +// Different subtype than the discriminator value for Employee+

      This triggers the following sql statement:
      [EL Fine]: 2013-05-22 06:31:28.156--ClientSession(94206285)--Connection(1671491267)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (ID, NAME, SUBTYPE) VALUES (?, ?, ?)
           bind => [1, some name, EMP]

      But when I query,
      EntityManager em = emf.createEntityManager();
      Query query = em.createQuery("select o from Employee o where o.name = 'some name'");
      Employee employee = query.getResultList().get(0);

      This prints the value of MGR.

      Does anyone know why is different subtype pushed to the DB and TLG?
        • 1. Re: Different behavior with TLG with inheritance based entity
          As it currently stands, there are two writable mappings for the "SUBTYPE" database field, which is not allowed in EclipseLink. If it is not throwing a warning, a bug should be entered so that it does.

          Changing this value is not supported, as you cannot change a java object into a different type by changing a flag. You haven't mentioned your setup, but it seems likely getting the cached version of the Employee - one that you just set the subtype attribute to be 'MGR' on back, it should show the version you set. You would need to refresh the object to be sure it is reading in the value from the datastore.