1 Reply Latest reply on Feb 24, 2008 8:30 AM by Daniel Tretter

    Entity Inheritence with primitive datatypes causes a Propert

    Daniel Tretter Newbie

      hi,
      when using entity inheritence with jboss 4.2.2 the EntityManager.find() call causes a

      org.hibernate.PropertyAccessException
      when called on superclass type and the subclass contains a field of primitive type.
      For example, i have two entities Person and Employee
      @Entity
      @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
      public class Person implements Serializable{
       @Id
       @Column(name="ID", nullable=false)
       private int id;
      
       @Column(name="NAME", nullable=false)
       private String name;
       // getter and setter.....
      }
      
      @Entity
      public class Employee extends Person implements Serializable {
      
       @Column(name="SSN", nullable=false)
       private int ssn;
       //getter and setter
      
      }
      


      now after persisting a Employee a call on
      entityManager.find(Person.class, id)
      will result in a PropertyAccessException:
      Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of org.example.entity.Employee.ssn

      the value in the database is not null, and it worked fine with JbossAS 4.0.5

        • 1. Re: Entity Inheritence with primitive datatypes causes a Pro
          Daniel Tretter Newbie

          after two days of debugging, it seems the embedded hsql database in JBoss4.2.2 creates a wrong result set from the join statement.

          The statement:

          select
           person0_.ID as ID0_0_,
           person0_.NAME as NAME0_0_,
           person0_.SSN as SSN1_0_,
           person0_.clazz_ as clazz_0_
          from
           (
           select
           null as SSN,
           NAME,
           ID,
           0 as clazz_
           from PERSON union select
           SSN,
           NAME,
           ID,
           1 as clazz_
           from Employee
           )
          person0_ where
           person0_.ID=?


          results in a unexpected NULL value in the SSN Field of the resultset. which causes Hibernate to produce the PropertyAccessError.

          with the hsqldb embedded in jboss 4.0.5 the statement produces a correct resultset.