1 Reply Latest reply on Aug 12, 2007 6:38 PM by tynor

    @Enumerated(EnumType.STRING) writes ordinal to table

    tynor

      JBoss AS 4.2.1

      I'm trying to persist an enum as a string (e.g. "OBJECT_CREATE" rather than its ordinal 0):

      public enum AuditEvent {
       OBJECT_CREATE,OBJECT_UPDATE,OBJECT_REMOVE,FIELD_CHANGE,
      }


      My Entity property is marked with @Enumerated to set the STRING converstion:

      @Column(name = "audit_event")
       @Enumerated(EnumType.STRING)
       public AuditEvent getEvent() {...


      The generated table is (correctly) a VARCHAR (without the STRING annotation, it is an int), but the value written to the table is still the ordinal value (the string '0' rather than the string 'OBJECT_CREATE').

      Is this a bug in JBoss 4.2.1, or a misunderstanding of the spec on my part?


        • 1. Re: @Enumerated(EnumType.STRING) writes ordinal to table
          tynor

          False alarm!

          After doing a clean deploy to jboss, it's working as expected (writing 'OBJECT_CREATE', etc. to the database, not a string ordinal value). Something must be wrong with my Seam "ant explode" task which I expected to deploy the new entity .class files to the server. In any case, JBoss/EJB3 is working as it ought to.

          Sorry for the wasted bandwidth!