4 Replies Latest reply on Sep 19, 2007 1:45 PM by alrubinger

    Problem with enum datatype

    imranpariyani

      hello

      I have a problem with the enum datatye. If i try to get an entity with enum as a field in it every thing works fine the problem occurs when i have a native query with only the enum field ..
      for example :

      String query = "SELECT DISTINCT type FROM card WHERE type IS NOT NULL ORDER BY type";
      return this.manager.createNativeQuery(query.toString()).getResultList();


      as output instead of the enum string i get only the first character .. here is the debug output of jboss

      2007-06-26 22:10:57,267 DEBUG [org.hibernate.SQL] SELECT DISTINCT type FROM card WHERE type IS NOT NULL ORDER BY type
      2007-06-26 22:10:57,316 TRACE [org.hibernate.type.CharacterType] returning 'M' as column: type
      2007-06-26 22:10:57,316 TRACE [org.hibernate.type.CharacterType] returning 'V' as column: type
      2007-06-26 22:10:57,317 TRACE [org.hibernate.type.CharacterType] returning 'E' as column: type
      2007-06-26 22:10:57,318 TRACE [org.hibernate.type.CharacterType] returning 'N' as column: type
      


      the question is why does it map the enum datatype of mysql to charactertype instead of string ..
      It sounds like a silly question but as i am new to ejb3 i had no other option but to ask :)

      Awaiting response ..

      thanks
      Imran

        • 1. Re: Problem with enum datatype
          fabryprog

          Please:
          - Post your entity class
          - Use HQL instead SQL



          FABRYPROG

          • 2. Re: Problem with enum datatype
            imranpariyani

             

            "FabryProg" wrote:
            Please:
            - Post your entity class
            - Use HQL instead SQL



            FABRYPROG


            I am not using HQL and am not mapping it to an entity ..

            i am using a nativequery here and the query looks like this
            String query = "SELECT DISTINCT type FROM card WHERE type IS NOT NULL ORDER BY type";
            return this.manager.createNativeQuery(query.toString()).getResultList();


            So if i get the entity then there is no problem since the enumerated column is mapped with
            @Enumerated(EnumType.STRING)

            is it possible to change the return type for a native query .. or somehow to tell ejb3 to map the enum type as string by default

            Regards

            Imran

            • 3. Re: Problem with enum datatype
              imranpariyani

              Well finally i figured it out.. applied a small patch to hibernate and build the source and replaced it with the original one ..

              Well if any one is stuck with similar kinda problem just let me know and i will send over the patch ..

              Regards

              Imran

              • 4. Re: Problem with enum datatype
                alrubinger

                Maybe ask the guys over on the Hibernate Developer's forums if they think you've discovered a bug, and if you patch would be worthwhile in the codebase?

                S,
                ALR