13 Replies Latest reply on Jan 22, 2009 6:14 AM by Alexey Kakunin

    Use server-side hibernate in web-application

    Alexey Kakunin Newbie

      Hi!
      I have followed problem with migration application worked on JBossAS 4.2.3 to JBossAS 5
      Environment used for testing: CentOS 5.2, Java 1.6.11, JBossAS5-jre6

      We have web-application (only war), used jbpm, so, used Hibernate. To minimize war-size to download, we are not including Hibernate, and some other libraries, already included into servre ClassPath. It's really allow us dramatically reduce size of war-file.

      In JBoss 4.2.x it works, but with JBoss 5.0 we received error:

      Caused by: java.io.FileNotFoundException: class path resource [org/jbpm/**/*.hbm.xml] cannot be opened because it does not exist
       at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:143)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:638)
       at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
      
      Looks like classLoader, used in JBoss5 cannot find resources (hibernate mapping).
      Are there any known issues about it for JBossAS 5?
      
      Any help will be very helpful!
      


        • 1. Re: Use server-side hibernate in web-application
          jaikiran pai Master

          Can you post the output of:

          jar -tf myapp.ear


          I'm interested in seeing where the org/.../.hbm.xml is located relative to the EAR root.

          • 3. Re: Use server-side hibernate in web-application
            Alexey Kakunin Newbie

            Hi!
            Actually, it is not ear, it is war. These resources are placed in jbpm-jpdl-3.3.1.GA.jar, what is located in EmForge.war/WERB-INF/libs

            Just checked - it does not depends - does hibernate included into war, or server's hibernate.jar is used - in both cases error is same

            • 4. Re: Use server-side hibernate in web-application
              Alexey Kakunin Newbie

              Ales, hi!
              Thank you very much for reply!

              So, is problem not in JBoss5, but in connection of JBoss5 & Latest Spring (2.5.6)?
              What is a possible workaround - place and configure to use VFS Resolved you pointed here: http://anonsvn.jboss.org/repos/jbossas/trunk/spring-int/src/main/org/jboss/spring/io/ ?

              Any temporary solutuion, helped to resolve problem will be helpful!

              • 5. Re: Use server-side hibernate in web-application
                Ales Justin Master

                 

                "akakunin" wrote:

                What is a possible workaround - place and configure to use VFS Resolved you pointed here: http://anonsvn.jboss.org/repos/jbossas/trunk/spring-int/src/main/org/jboss/spring/io/ ?

                This is actually not a workaround, this is the proper solution,
                at least until Spring changes its Resources impl to be less plain JDK's URL dependant.

                You can either build the resources on your own,
                or use this:
                - http://downloads.sourceforge.net/jboss/jboss-spring-3.1.jar?modtime=1215264368&big_mirror=1

                Then simply drop this jar into appropriate place.
                * your apps classpath
                * common/lib


                • 6. Re: Use server-side hibernate in web-application
                  Ales Justin Master

                   

                  "alesj" wrote:

                  You can either build the resources on your own,
                  or use this:
                  - http://downloads.sourceforge.net/jboss/jboss-spring-3.1.jar?modtime=1215264368&big_mirror=1

                  Although I suggest building it on your own,
                  as I remember I just recently did some changes to the codebase.
                  (some VFS cache usage, to optimize resources lookup)

                  • 7. Re: Use server-side hibernate in web-application
                    Alexey Kakunin Newbie

                    Ales, thank you very much again!
                    it looked for me quite strange. JBoss5 just out, but raising very fast. Spring - is one of the most (probably the most) popular framework in the java.
                    And these two tools is not compatible out-of-box.

                    I hope it is not for a long time - but you need more promotion for your project, to avoid people spent time for these compatibility problems like I did :)

                    Last question - does jboss-spring available somewhere on maven repository?

                    Thanks again!

                    • 8. Re: Use server-side hibernate in web-application
                      Ales Justin Master

                       

                      "akakunin" wrote:

                      And these two tools is not compatible out-of-box.

                      Apart from this, I'm not familiar with any other non-compatibilities.
                      This one is just unfortunate, to base its scanning on JDK's FS api - which is horrible. ;-)
                      There will be new FS in JDK7 afaik.

                      "akakunin" wrote:

                      I hope it is not for a long time - but you need more promotion for your project, to avoid people spent time for these compatibility problems like I did

                      I'm still waiting some response from SS side - see the JIRA issue.
                      On what exactly to do - how to ship this piece.

                      "akakunin" wrote:

                      Last question - does jboss-spring available somewhere on maven repository?

                      Yes, it's part of JBossAS maven resources:
                      - http://anonsvn.jboss.org/repos/repository.jboss.org/maven2/org/jboss/jbossas/jboss-as-sprint-int/5.0.0.GA/

                      But I'll also attach a snapshot jar to JIRA issue.

                      • 9. Re: Use server-side hibernate in web-application
                        Alexey Kakunin Newbie

                        Hi, I have some updates on this problem.

                        So, first of all, way I configured hibernate (and as result, error message I received from JBossAS5) was incorrect. I received same error on JBoss 4.2.3. Actually it is because then I received first error about resources, I started to experiment and it produced this problem.

                        So, in my case, path to hibernate mappings are configured like:

                         <property name="mappingLocations">
                         <list>
                         <value>classpath*:/org/jbpm/**/*.hbm.xml</value>
                         <value>classpath*:/org/emforge/**/*.hbm.xml</value>
                         <value>classpath*:/ru/emdev/**/*.hbm.xml</value>
                         </list>
                         </property>
                        

                        As you can see - classpath* is used.

                        With this settings everything working fine under JBoss 4.2.3, but, under JBoss 5 I received error like:

                        Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:/org/jbpm/**/*.hbm.xml] at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)
                        


                        So, it looks like somebody (Spring, JBoss?) stopped to understand classpath*

                        I've placed proposed jboss-as-spring-int into war (only this jar, without any of it's dependencies) - but, it did not help. I've still receiving this error.

                        Any suggestions?

                        • 10. Re: Use server-side hibernate in web-application
                          Ales Justin Master

                           

                          "akakunin" wrote:

                          I've placed proposed jboss-as-spring-int into war (only this jar, without any of it's dependencies) - but, it did not help. I've still receiving this error.

                          Just placing that jar there is not enough. ;-)
                          You need to specify that you want to use that VFS resource pattern resolver:
                          public class NamedXmlApplicationContext extends ClassPathXmlApplicationContext implements Nameable
                          {
                           private String defaultName;
                           private Resource resource;
                           private NamedXmlBeanDefinitionReader beanDefinitionReader;
                          
                           public NamedXmlApplicationContext(String defaultName, Resource resource) throws BeansException
                           {
                           this(defaultName, resource, true);
                           }
                          
                           public NamedXmlApplicationContext(String defaultName, Resource resource, boolean refresh) throws BeansException
                           {
                           //loading config from Resource
                           super(new String[]{}, false);
                           this.defaultName = defaultName;
                           this.resource = resource;
                           if (refresh)
                           {
                           refresh();
                           }
                           }
                          
                           protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException
                           {
                           // Create a new XmlBeanDefinitionReader for the given BeanFactory.
                           beanDefinitionReader = new NamedXmlBeanDefinitionReader(beanFactory);
                          
                           // Configure the bean definition reader with this context's
                           // resource loading environment.
                           beanDefinitionReader.setResourceLoader(this);
                           if (getClassLoader() != null)
                           beanDefinitionReader.setBeanClassLoader(getClassLoader());
                           beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
                          
                           // Allow a subclass to provide custom initialization of the reader,
                           // then proceed with actually loading the bean definitions.
                           initBeanDefinitionReader(beanDefinitionReader);
                           loadBeanDefinitions(beanDefinitionReader);
                           }
                          
                           protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException
                           {
                           reader.loadBeanDefinitions(resource);
                           }
                          
                           public String getName()
                           {
                           String name = beanDefinitionReader.getName() != null ? beanDefinitionReader.getName() : defaultName;
                           if (name == null)
                           throw new IllegalArgumentException("Bean factory JNDI name must be set!");
                          
                           return name;
                           }
                          
                           // HERE!!
                           protected ResourcePatternResolver getResourcePatternResolver()
                           {
                           return new VFSResourcePatternResolver(getClassLoader());
                           }
                          }
                          

                          This is how I do it in my SpringDeployer's ApplicationContext,
                          dunno how you can set this via configuration.
                          Perhaps Spring picks-up ResourcePatternResolver via PostBeanProcessor's type matching?

                          • 11. Re: Use server-side hibernate in web-application
                            Alexey Kakunin Newbie

                            Ales!
                            Thanks for note.
                            In my case I fixed problem by changing classpath* to the list of concrete classpath (without using any wildcards)
                            Did not finish complete testing - but looks like started to work

                            Thank you for all your help!

                            • 12. Re: Use server-side hibernate in web-application
                              Ales Justin Master

                               

                              "akakunin" wrote:

                              In my case I fixed problem by changing classpath* to the list of concrete classpath (without using any wildcards)
                              Did not finish complete testing - but looks like started to work

                              So, you're are now using the VFSResourcePatternResolver or not?
                              If yes, how did you enable it (so other users might do the same)?



                              • 13. Re: Use server-side hibernate in web-application
                                Alexey Kakunin Newbie

                                Ales, hI!
                                I just checked:
                                1. Removed jboss-spring from my project
                                2. Changed classpath* to list of individual classpath
                                Everything started to work.

                                So, for my case problem was in classpath*. Probably, it may be resolved with using VFS Resolver - but I don't know. For my case solution was to avoid using of classpath*