6 Replies Latest reply on Aug 9, 2010 9:20 AM by charles_a

    Variables types / String too large for column

    charles_a

      Hi guys,

       

      I´ve the following problem with the variables types in JBPM 4.4: When we store a large String as process variables, we get a hibernate exception during the saving. As far as I can see, the String is simply too large for the target column. It´s defined as VARCHAR2(255).

       

      We currently use a serializable container object to store only one String value in it. That way it´s put in the JBPM_LOB table, everything is fine. Am I missing something? Is there a better way to deal with it?

       

      If not, we will be forced to always use container objects as the content of variables is dynamic and can be of arbitrary size.

       

      Btw, we use the same trick to deal with Hibernate objects. We have unsaved Hibernate objects we want to pass along as process variables. Seems trivial, but doesn´t work, because jbpm tries to save only the it´s id as a reference to this object (leading to an exception in our case). That´s annoying and we´re also using a container object here. Again, it works but doesn´t feel good.

       

      Fiddling around with the types.xml would feel even worse ;-) Any options?

       

      Cheers,

      Charles

        • 1. Re: Variables types / String too large for column
          mwohlf

          the following hackery stores a variable in the TEXT_VALUE_ column of JBPM4_VARIABLE:

           

                  EnvironmentImpl environment = processEngine.openEnvironment();
                  try {
                      taskImpl.createVariable("varName", "a real long text value here".toCharArray(), "char[]", false);
                  } finally {
                      environment.close();
                  }

           

          HTH

          Michael

          • 2. Re: Variables types / String too large for column
            charles_a

            Hi Michael,

             

            I´ll give it a try. But as you say, this also is a hack. But I think a better hack than our container object hack

             

            Are there any plans to improve the "variable type handling" in jbpm? As stated in my initial post, we also had trouble with hibernate objects that we would like to handle as simple serializable objects. Sometimes it would be helpful to define the type manually or have more control in some way. Is there anything in jira around this topic?

             

            Cheers,

            Charles

            • 3. Re: Variables types / String too large for column
              rebody

              Hi Charles,

               

              Please try this codes:

               

              executionService.setVariable("largeString", largeString.toCharArray());

               

              or

               

              executionService.setVariable("blob", largeString.getBytes("UTF-8"));

              • 4. Re: Variables types / String too large for column
                charles_a

                Hi Huisheng,

                 

                looks even better. But with this (and Michaels) way, we´re unable to use the String value of the variable in expression language. For example, if we store a lot of users comma separated in this variable and want them to receive a mail, we get a ClassCastException as char[] is not a subclass of String.

                 

                Probably we´ll stick with our container object, because here we can simple use the getter to receive the String in expression language, i. e. ${myvar.value}. Not nice, but works.

                 

                Huisheng, any ideas how to tweak jbpm to get the char[] working in EL like a regular String variable?

                 

                Cheers,

                Charles

                • 5. Re: Variables types / String too large for column
                  rebody

                  Actually,  there is no easy way to convert char[] to string.  You must create a bean a export this bean to the jbpm.cfg.xml,  like <object name="myConverterBean" class="my.converterBean"/>, then use this bean to convert char[] to String.  like #{myConverterBean.convert(charArray)}.

                   

                  Hmm~,  I see.  Seems we should provide a way to auto-detect how to store long string.

                  • 6. Re: Variables types / String too large for column
                    charles_a

                    One thing to keep in mind is, that users may be querying the database directly. If it´s stored in the one or another column based on the length of the string... it could be confusing. That´s why I would propose to explicitly define if it should be stored as a "long" or "short" string.

                     

                    Charles