1 Reply Latest reply on Feb 16, 2006 3:24 PM by elkner

    enum as primary-key

    jzmmek2k2

      I am really impressed by the current EJB3 implementation, but got a question about enums in entities.

      Is it possible to use an enum as primary-key (@Id) of an entity ?

      I tried the following two solutions:
      ----------------------

      1.) Adding "@Id" on the enum-typed property, which results in a byte-array-datatype.

      2.)

      @Embeddable
       public enum GenderType
       {
       MAN,WOMAN;
      
       public int getOrdinal()
       {
       return ordinal();
       }
      
       public void setOrdinal(int ordinal)
       {
       }
       }

      This compiles fine and the automatically generated schema is correct,
      but when referencing the entity-bean I got the following exception:

      No default constructor for entity: de.jitek.component.friendler.entity.GenderType


      ----------------------

      Can we map an enum as primary-key at all ?

      An example would great, even if it would require hibernate-specific extensions.



      Any help would really appreciated,

      Regards
      Jan