7 Replies Latest reply on Jul 11, 2012 1:55 AM by jaikiran

    jboss-as-7.0.2.Final - /hibernate.cfg.xml not found

    srikrishnak

      Hi,

      We have a REST application working fine in jboss-6.0.0.Final which we want to migrate to jboss-as-7.0.2.  When I deploy the war file to jboss-as-7.0.2 it gives me an error saying "Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found".  hibernate.cfg.xml file is located in WEB-INF/classes/ folder.  I tried moving the file around (WEB-INF/ folder, WEB-INF/lib/ folder, root folder (/)) but no luck.  Project is setup as a "Dynamic Web Project" in Eclipse and I use jboss tools to generate the war file.  Directory structure is as follows and nothing fancy.  

       

      Example.war - 
          META-INF
              MANIFEST.MF
          WEB-INF
              classes
                  hibernate.cfg.xml
                  example-infinispan.xml
                  com/*               
              lib
              web.xml 
      
      

       

      When I create SessionFactory instance, I do the following:

       

      sessionFactory = new Configuration().configure().buildSessionFactory();
      

       

      To test it out, if I try to load hibernate.cfg.xml from an external path (Ex: jboss-as-7.0.2.Final/hibernate/hibernate.cfg.xml), jboss-as-7.0.2 finds hibernate.cfg.xml file, but the same problem arises when it's trying to load all the *.hbm.xml files defined in hibernate.cfg.xml file. 

       

      String hibernateConfigFilePath = System.getProperty("user.dir") + System.getProperty("file.separator") + "hibernate" + System.getProperty("file.separator") + "hibernate.cfg.xml";
      Configuration configuration = new Configuration();
      configuration.configure(new File(hibernateConfigFilePath));
      sessionFactory = configuration.buildSessionFactory();
      

       

       

      One more important detail here is, I get the same error in both modes (domain & standalone) even though my focus is to make this work in domain mode.

       

      Thoughts? 

       

      Thanks

      Srikrishna Kalavacharla

        • 1. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
          smarlow

          It probably won't make a difference but could you try to recreate with the nightly build?  Link for the nightly build is community.jboss.org/thread/167590

           

          How are you associating your web application with the Hibernate jars?  Perhaps adding a dependency on the shared "org.hibernate" module?  Or including Hibernate jars with the application?  If your including Hibernate jars with the application, which version of Hibernate are you including?

          • 2. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
            srikrishnak

            Hi Scott,

            Thanks for the reply.  Sorry, I missed to give out the detail about how I added hibernate.  Yes, through META-INF/MANIFEST.MF file as follows:

             

            "Dependencies: org.hibernate, org.apache.log4j"

             

            I'll try out the nightly build and will let you know.

             

            Thanks

            Srikrishna Kalavacharla

            • 3. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
              srikrishnak

              Hi Scott,

              I've tried the nightly build you have suggested (jboss-as-7.1.0.Alpha2-SNAPSHOT) and as you have suspected, it did not make any difference and I still get the same error as follows:

               

              Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found

               

              Thanks

              Srikrishna Kalavacharla

              • 4. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
                smarlow

                Hi Srikrishna,

                 

                I would like to see the exception call stack that goes with the HibernateException, could you attach the as7/standalone/logs/server.log file (or a http://pastebin.com link to the contents).

                 

                Scott

                • 5. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
                  srikrishnak

                  Hi Scott,

                  I've fixed the issue by copying all the jar files into WEB-INF/lib folder.  Now I'm trying to upgrade to 7.1.1.Final, I'm facing the same issue.  I've tried doing the same (copying modules/org/hibernate/* jar files to WEB-INF/lib folder), but it did not do the trick this time.  I've also tried moving the hibernate.cfg.xml around and trying to load it from a specific location (EX: "/com/companyname/repository/pojo/hibernate.cfg.xml") but with no luck.  I'm thinking of trying to add a persistence.xml file in META-INF folder and also try adding a jboss-deployment-structure.xml file.  Do you have any suggestions? 

                   

                  Thanks

                  Srikrishna Kalavacharla

                  • 6. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
                    srikrishnak

                    If you try loading hibernate resources using a static block and if you try accessing these resources before the caller finishes initialization (Ex: before @PostConstruct is called or in the Constructor), you get this issue.  Moving the logic which calls hiberante resources to @PostConstruct in case of a @Singleton and calling the resources in a non-static way, resolves this issue.

                    • 7. Re: jboss-as-7.0.2.Final - /hibernate.cfg.xml not found
                      jaikiran

                      I thought we had fixed the issue where the classloader wasn't being set to the deployment classloader when the component classes were being loaded and their static block was being executed. Would you be able to attach a simple application which reproduces this?