3 Replies Latest reply on Feb 28, 2009 5:26 AM by fero kocun

    PVM HibernateLongVariable

    fero kocun Newbie

      Hi,
      I encounter following problem in PVM. TypeMapping for HibernateLongInstance has a ClassNameMatcher with "hibernate" as claa name and not HibernateLongIdMatcher. I have used default pvm.variable.types.xml

      <type class="hibernate" id-type="long" variable-class="org.jbpm.pvm.type.variable.HibernateLongVariable" />


      Where is the problem? I think that xml does not configure another than
      ClassNameMatcher.

      Thanks for reply

      Fero

        • 1. Re: PVM HibernateLongVariable
          fero kocun Newbie

          There was a bug in method VariableTypesBinding.parseTypeMapping(). It expected "class" attribute in xml to be set to "persisted" and I chcnged it to "hibernate":

          // if type="hibernate"
           } else if ("hibernate".equals(className)) {


          But I think code in HibernateLongIdMatcher is broken as well.
          if (environment!=null) {
           SessionFactory sessionFactory = (SessionFactory) environment.get("hibernate.session.factory");
           if (sessionFactory!=null) {
           ClassMetadata classMetadata = sessionFactory.getClassMetadata(value.getClass());
           matches = ( (classMetadata!=null)
           && (classMetadata.getIdentifierType().getClass()==LongType.class)
           );
           }


          First you should to ask if value is not a HibernateProxy cos in that case you wont get any metadata (as done in jBPM 3)..
           Class valueClass = value.getClass();
           if (value instanceof HibernateProxy) {
           valueClass = valueClass.getSuperclass();
           }


          And second. How can you get SessionFactory from envoronment? The interface has only addContext(Context) method and SessionFactory does not implemenst Context. But maybe I shoul implement my own Environment and fill it in another way than throgh Environment interface. Maybe my bad.

          What do you think?

          Thanks

          Fero

          • 2. Re: PVM HibernateLongVariable
            fero kocun Newbie

            BTW wouldn't it be better to use Digester for parsing. It is faster (SAX no DOM), declarative, easy to use and you can do really complicated parsing implementing its interfaces.. And if you want both directions xml2java and java2xml, why not to use Castor? But I don't have big experienced with it. But I think it should be good solution..

            Fero

            • 3. Re: PVM HibernateLongVariable
              fero kocun Newbie

               

              "frantisek.kocun@gmail.com" wrote:
              And second. How can you get SessionFactory from envoronment? The interface has only addContext(Context) method and SessionFactory does not implemenst Context. But maybe I shoul implement my own Environment and fill it in another way than throgh Environment interface.


              I was wrong. I didn't understand how context works. So the PVM code is good and really very useful. I implemented my own HibernateContext and it was easy..

              Fero