3 Replies Latest reply on Dec 22, 2008 8:14 PM by Ronald van Kuijk

    Converters saving problem

    fero kocun Newbie

      we use open session in view. I would like to store some Booleans to db, it is stored, but no converter is set, so it si later read as String, which makes Exception.

      Problem is that when I set variables their values are converted with converters. To find the right converter Converters.getConverterMaps() is used. It creates new converter map for given objectFactory. But when when values are stored, ConverterEnumType ask Converters for id Converters.getConverterId((Converter) value); . It uses the same method Converters.getConverterMaps() but with different object factory. Converters to convertersMap are created again and the key to map is converter itself (not its class) so method Converters.getConverterId(Converter converter) returns null. Why two different object factories are used in single request? There is the same session. My middle layer code looks like this:

      public void startProcess(final StartEvent startEvent, final String transition){
      getTemplate().execute(new JbpmCallback(){
      public Object doInJbpm(JbpmContext context) throws JbpmException{
      org.jbpm.graph.exe.ProcessInstance processInstance = context.newProcessInstanceForUpdate(startEvent.getProcess().getName());
      return null;

      We use spring jbpm module and spring is configured so that callback is wrapped in transaction. But all the actions form single request are in one session (open session in view) and every in its own transaction. But this time the only action was startProcess.

      StartEvent is our class which implements map for process variables, and is typed (has process as attribute).

      Thanks for your help


        • 1. Re: Converters saving problem
          fero kocun Newbie

          I know exactly where the problem is but I don't know the best way to solve it.

          The problem is I have two JbpmConfigurations. It is ok that there is no current JbpmContex, when saving process instance by hibernate, because jbpmContext is closed and it uses default JbpmConfiguration which should have the same objectFactory. But it does't because context was created on another configuration.

          Why I have 2 JbpmConfigurations? First is created when hibernate is scanning classes for mapping. Class org.jbpm.job.Timer is persistent and it has static attribute:
          static BusinessCalendar businessCalendar = new BusinessCalendar();

          Constructor of BusinessCalendar look like this:
           public static synchronized Properties getBusinessCalendarProperties() {
           if (businessCalendarProperties==null) {
           String resource = JbpmConfiguration.Configs.getString("resource.business.calendar");
           businessCalendarProperties = ClassLoaderUtil.getProperties(resource);
           return businessCalendarProperties;
           public BusinessCalendar() {

          So this creates first Configuration.

          Second is created programmatically as a Spring bean and injected into JbpmTemplate.
           <!-- jBPM configuration -->
           <bean class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean" id="jbpmConfiguration">
           <property name="sessionFactory" ref="sessionFactory"/>
           <property name="configuration" value="classpath:jbpm.cfg.xml"/>
           <property name="processDefinitionsResources">
           <!-- jBPM template -->
           <bean class="org.springmodules.workflow.jbpm31.JbpmTemplate" id="jbpmTemplate">
           <property name="jbpmConfiguration">
           <ref bean="jbpmConfiguration"/>
           <property name="hibernateTemplate">
           <ref bean="hibernateTemplate"/>

          Problem is that this configuration is not in static map JbpmConfiguration.instances because it is created this way:
          ObjectFactory jbpmObjectFactory;
           // 1. create the configuration from the file
           if (configuration != null) {
           logger.info("creating JbpmConfiguration from resource " + configuration.getDescription());
           InputStream stream = configuration.getInputStream();
           jbpmObjectFactory = ObjectFactoryParser.parseInputStream(stream);
           jbpmObjectFactory = objectFactory;
           jbpmConfiguration = new JbpmConfiguration(jbpmObjectFactory);

          So what should I do? I think this is wrong way and they should use JbpmConfiguration getInstance(String resource) to create configuration. Have anyone experience with spring module?

          Thanks a lot


          • 2. Re: Converters saving problem
            fero kocun Newbie

            I got it working by editing spring jbpm module. But don't know it is done as good as it can be.
            Instead of new JbpmConfiguration(...) I use JbpmConfiguration.getConfiguration(..)

            So question is simplier:

            a) Should I commit transaction before closing context:

            tx start
            new jbpmcontext
            do something
            tx commit
            jbpmcontext close

            b) Or should I work with only one jbpmconfiguration = only one object factory and use jbpmcontext like this

            tx start
            new jbpmcontext
            do something
            jbpmcontext close
            tx commit
            This fits me. I need only 1 configuration. But I don't like the static default when there is no jbpm context.
            Answers please:-)

            • 3. Re: Converters saving problem
              Ronald van Kuijk Master

              b, otherwise things are nested strangely