6 Replies Latest reply on May 15, 2006 1:58 PM by Brice Ruth

    Storing an Enum in a VariableInstance

    Brice Ruth Newbie

      What's the best way of storing an Enum in a VariableInstance? I've created a converter, but I think that only gets me part of the way there ... if I need to drop to Hibernate and run a query (using the Criteria API) against a TaskInstance, I cannot pass in my Enum value - it gives me a ClassCastException because the converter uses StringInstance to store the Enum value, and the Hibernate API tries to cast my Enum query parameter to a String in StringType.toString.

      Not sure if this is a question better asked in the Hibernate forums, if so, just let me know. Thanks!

        • 1. Re: Storing an Enum in a VariableInstance
          Brice Ruth Newbie

          I'll throw this over to the Hibernate guys and see if I get any ideas from them.

          • 2. Re: Storing an Enum in a VariableInstance
            Alejandro Guizar Master

            Persistence of JDK 1.5 enums has been deeply discussed in Persisting jdk1.5 enums today, a topic in the Hibernate forum. It looks like Hibernate annotations comes with a user type for enums.

            For jBPM we have to figure out a way not to introduce a new VariableInstance subclass just for enums, and retain JDK 1.4.2 compatibility.

            • 3. Re: Storing an Enum in a VariableInstance
              Brice Ruth Newbie

               

              "alex.guizar@jboss.com" wrote:
              Persistence of JDK 1.5 enums has been deeply discussed in <a href="http://forum.hibernate.org/viewtopic.php?t=933393">Persisting jdk1.5 enums today</a>, a topic in the Hibernate forum. It looks like Hibernate annotations comes with a user type for enums.

              For jBPM we have to figure out a way not to introduce a new VariableInstance subclass just for enums, and retain JDK 1.4.2 compatibility.


              Sounds like there's some thinking going on for this. That's a good thing (tm).

              What, if anything, can I do now?

              One note - why would JDK 1.4.2 compatibility be an issue, since Enums aren't supported < 1.5? What would the solution look like if 1.4.2 compatibility were not an issue? I seem to have a working EnumConverter for JBPM, but I can't figure out a way of letting Hibernate know how to convert to/from an enum when I'm not calling through the JBPM API. i.e. I cannot create a Criteria and use an enum directly in a variableInstances subcriteria.

              Incidentally, I can't even seem to pass in the String value created by the Converter (a kludge) - Hibernate doesn't throw an Exception, but it returns zero rows. Not sure why this is. The SQL query Hibernate generates (logging=DEBUG) seems to work when I run it manually.

              • 4. Re: Storing an Enum in a VariableInstance
                Alejandro Guizar Master

                 

                "bdruth wrote:
                What, if anything, can I do now?

                This is the easiest route that comes to mind:
                add hibernate annotations to the classpath
                subclass VariableInstance
                declare a field of type Enum
                map the subclass to the database with the org.hibernate.type.Enum type
                Remarks:
                the topic in the hibernate forum is not clear on whether you can use enums in queries; we need to make sure the enum support includes criteria
                this solution, and any other, is specific to java 5; it cannot go to the core jbpm codebase
                jbpm users that do not deal with enums do not want the additional subclass and database column(s)
                conversely, users that deal with enums probably do not mind the extra subclass and column(s)
                My conclusion is that we should consider a separate subproject, some sort of java 5 bonus pack, that java 5 users can install to get enum support and any other goodie we come up with in the future.

                • 5. Re: Storing an Enum in a VariableInstance
                  Alejandro Guizar Master

                  jBPM team: any thoughts on this?

                  • 6. Re: Storing an Enum in a VariableInstance
                    Brice Ruth Newbie

                     

                    "alex.guizar@jboss.com" wrote:
                    "bdruth wrote:
                    What, if anything, can I do now?

                    This is the easiest route that comes to mind:
                    <ol><li>add hibernate annotations to the classpath</li>
                    <li>subclass VariableInstance</li>
                    <li>declare a field of type Enum</li>
                    <li>map the subclass to the database with the org.hibernate.type.Enum type</li></ol>


                    OK, so - mapping the subclass to the database, is that done using annotations, or am I creating an .hbm.xml file? Does this get me generic Enum support, or do I need to do something for each different Enum (TaskStatus, DocumentType, etc.) that I create?

                    Also, looks like the latest release of hbn annotations requires hbn 3.2.0cr2 - am I to presume that this is compatible with JBPM? Do you guys test all the hbn streams against JBPM?