5 Replies Latest reply on Oct 18, 2007 11:59 AM by mputz

    About loading of hibernate configuration in HibernateHelper.

    quepasa

      First, i want to sorry for my very intermediate english :)

      So... in jBPM config-file (jbpm.cfg.xml) exists a string


      when i try to execute this code

      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       try {
       jbpmContext.deployProcessDefinition(processDefinition);
       } finally {
       jbpmContext.close();
       }
      


      there exception throws with message Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found.

      now see the full stack trace:

      Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
       at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
       at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
       at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
       at org.jbpm.db.hibernate.HibernateHelper.createConfiguration(HibernateHelper.java:91)
       at org.jbpm.persistence.db.DbPersistenceServiceFactory.getConfiguration(DbPersistenceServiceFactory.java:69)
       at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:91)
       at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:95)
       at org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:99)
       at org.jbpm.persistence.db.DbPersistenceService.getGraphSession(DbPersistenceService.java:341)
       at org.jbpm.JbpmContext.getGraphSession(JbpmContext.java:571)
       at org.jbpm.JbpmContext.deployProcessDefinition(JbpmContext.java:173)
       at ru.emd.escom3.core.CoreTest.main(CoreTest.java:52)


      and the cause of this exception is that the HibernateHelper.java trying to use specified hibernate's config-file like a resource in the class path. Look here:

      public abstract class HibernateHelper {
      ...
       public static Configuration createConfiguration(String cfgXmlResource, String propertiesResource) {
      ....
       // if a special hibernate configuration xml file is specified,
       if (cfgXmlResource!=null) {
       // use the configured file name
       log.debug("creating hibernate configuration resource '"+cfgXmlResource+"'");
       configuration.configure(cfgXmlResource);
       } else {
       log.debug("using default hibernate configuration resource (hibernate.cfg.xml)");
       configuration.configure();
       }
      ....
       }
      }
      


      here we can see, that
      configuration.configure(cfgXmlResource);
      is called when config-file is a xml-file (it's my case).

      And the configuration is the instance of Configuration class (it is in hibernate source code), and method configure() of this class trying to load transmitted file-name like a resource.

      BUT MY hibernate.cfg.xml IS NOT A RESOURCE.

      It is an ordinary file on file system, and i have a question: how to use such hibernate's config-file in this case ?

        • 1. Re: About loading of hibernate configuration in HibernateHel
          quepasa

          *So... in jBPM config-file (jbpm.cfg.xml) exists a string:

          • 2. Re: About loading of hibernate configuration in HibernateHel
            quepasa

            Damn, xml formatted data is not supported in this forum :(

            so, those xml is:

            string name="resource.hibernate.cfg.xml"

            value="/hibernate.cfg.xml"

            • 3. Re: About loading of hibernate configuration in HibernateHel
              mputz

              by default, the hibernate.cfg.xml and jbpm.cfg.xml files are residing in the same directory, often bundled within a jar:

              [mputz@mputz lib]$ jar -tvf jbpm-configs.jar
               0 Thu Aug 30 01:05:28 CEST 2007 META-INF/
               71 Thu Aug 30 01:05:28 CEST 2007 META-INF/MANIFEST.MF
               18765 Thu Sep 27 15:34:52 CEST 2007 hibernate.cfg.xml
               2978 Wed Oct 17 11:35:56 CEST 2007 jbpm.cfg.xml
               735 Mon Jun 11 14:22:10 CEST 2007 jbpm.mail.templates.xml
              


              and the configuration property in jbpm.cfg.xml contains no leading slash:

              <string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />


              • 4. Re: About loading of hibernate configuration in HibernateHel
                quepasa

                And what ?

                Ok, there my mistake with leading slash in configuration property "resource.hibernate.cfg.xml". But i've tested it without this slash too - and the algorithm of hibernate's config file loading was same as described before, in my previous post.

                What if i do not want to store hibernate's config file in the jar-file ?
                What if i use a jbpm-jpdl.jar lika a ordinary library in my jboss deployable web-module ? Tell me, please, where i need to store hibernate.cfg.xml in that case ?

                • 5. Re: About loading of hibernate configuration in HibernateHel
                  mputz

                  If you don't want the *cfg.xml files in a separate jar, you could include it in the classpath, for a web-app this would be WEB-INF/classes. Here is a (partial) listing of a modified jbpm-console.war, where the configs are taken from the WEB-INF/classes folder.

                  ./jboss-console.war
                  images
                  index.jsp
                  META-INF
                  sa
                  ua
                  WEB-INF
                  
                  ./WEB-INF/classes:
                  hibernate.cfg.xml
                  jbpm.cfg.xml
                  jbpm.mail.templates.xml
                  messages.properties
                  
                  ./WEB-INF/lib:
                  el-api.jar
                  el-ri.jar
                  gravel.jar
                  jbpm4jsf.jar
                  jbpm-identity.jar
                  jbpm-jpdl.jar
                  jsf-api.jar
                  jsf-facelets.jar
                  jsf-impl.jar
                  


                  Is that coming close to what you are trying to do?