4 Replies Latest reply on Oct 14, 2005 4:49 AM by Brian

    java 1.5 enums and Mysql

    Brian Newbie

      Hi all,

      I'm using jdk 1.5 persisted enums referenced in my ejb3 entity beans. I'm also using Mysql. They seem to be being persisted in the database as Blobs. Has anyone else used these and seen this?

      thanks,
      Brian

        • 1. Re: java 1.5 enums and Mysql
          Jonn Beames Newbie

          I am using enums as field in my entities and am using MySQL 4.1 and I am not seeing my enums persisted as blobs.

          Originally I created my table manually and created the columns that hold the enum values as varchars. An enum would get inserted into the table as its text value. Later, I let hbm2ddl create my tables and it created the enum columns as integers in which the enum gets persisted as its ordinal value.

          In either case the persistance layer handles the enums appropriately and the app sees them as expected.

          Sorry that I can't second your experience, but thought more info may be helpfull,
          Jonn

          • 2. Re: java 1.5 enums and Mysql
            Brian Newbie

            Thanks Jonn,

            I really appreciate it. I have a few questions for you if you don't mind.

            1) I'm letting the database get created automatically on deployment of the ear. Is that what you mean by hbm2dll?

            2) Can you tell me what version of jboss and of the ejb3 release you're using?

            thanks so much again for the reply,

            cheers,
            Brian

            • 3. Re: java 1.5 enums and Mysql
              Jonn Beames Newbie

               

              1) I'm letting the database get created automatically on deployment of the ear. Is that what you mean by hbm2dll?

              Yes. I set the "hibernate.hbm2ddl.auto" property to "update" in persistance.xml, dropped my tables manually, deployed my ear and the tables were recreated with enum columns created as type INTEGER.

              2) Can you tell me what version of jboss and of the ejb3 release you're using?

              I started out using AS 4.0.3RC2 with the provided version of EJB3 (when I was using the manually created table). I switched to AS 4.0.3 plus EJB-3.0_RC3 a couple of days ago (this is the version I was using while doing auto table creation experiments).

              My enums are really simple right now. Example:
              public enum MpaRating {
               NAV, G, PG, PG13, R, NC17, NR;
              
               public String getDescription() {
               switch (this) {
               case G: return "G";
               case PG: return "PG";
               case PG13: return "PG-13";
               case R: return "R";
               case NC17: return "NC-17";
               case NR: return "NR";
               case NAV:
               default: return "--";
               }
               }
              }
              And are used in enties like:
              @Entity
              @Table(name = "MOVIES")
              public class Movie {
               private long id;
               private String title;
              ...other fields...
               private MpaRating mpaRating;
              
               @Id(generate = GeneratorType.AUTO)
               public long getId() {
               return id;
               }
               public void setId(long id) {
               this.id = id;
               }
               public String getTitle() {
               return title;
               }
               public void setTitle(String title) {
               this.title = title;
               }
              ...other getters and setters...
               public MpaRating getMpaRating() {
               return mpaRating;
               }
               public void setMpaRating(MpaRating mpaRating) {
               this.mpaRating = mpaRating;
               }
              }


              I hope this helps,
              Jonn

              • 4. Re: java 1.5 enums and Mysql
                Brian Newbie

                This really helps Jonn, thanks so much. I'm sure I'll get it working now.