9 Replies Latest reply on Feb 26, 2013 8:11 AM by mbickel

    ClassCastException deploying Hibernate Search 4.x

    mbickel Newbie

      Hi all,

       

      I'm migrating from Seam2.2/JBoss AS4.2 and have upgraded to Hibernate 4.1.1 in the process. The jar files are shipped within my ear and thus I added an exclusion in my deployment file:

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
        <deployment>
            <exclusions>
              <module name="org.hibernate" />
            </exclusions>
      

       

      My project also requires Hibernate Search. So I added hibernate-search-{analyzers,engine,orm}.jar to my ear lib directory. All jars are from the Hibernate Search 4.1.0 distribution.

       

      While deploying my application I get the following error:

       

      15:33:41,381 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.persistenceunit."proj.ear/proj.jar#proj": org.jboss.msc.service.StartException in service jboss.persistenceunit."proj.ear/proj.jar#proj": Failed to start service
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.6.0_24]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.6.0_24]
          at java.lang.Thread.run(Thread.java:679) [rt.jar:1.6.0_24]
      Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype
          at java.util.ServiceLoader.fail(ServiceLoader.java:231) [rt.jar:1.6.0_24]
          at java.util.ServiceLoader.access$300(ServiceLoader.java:181) [rt.jar:1.6.0_24]
          at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:369) [rt.jar:1.6.0_24]
          at java.util.ServiceLoader$1.next(ServiceLoader.java:445) [rt.jar:1.6.0_24]
          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:251)
          at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:53)
          at org.hibernate.service.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:120)
          at org.hibernate.ejb.Ejb3Configuration.buildLifecycleControledServiceRegistry(Ejb3Configuration.java:924)
          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:903)
          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
          at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
          ... 3 more
      

       

      I've checked the jar and verified org.hibernate.search.hcore.impl.HibernateSearchIntegrator does indeed implement the mentioned interface (duh!).

      So I hazard a guess that this is a classloader issue. But what I can't get my head around is why this occurs even when both libs are packaged in my ear. So - help?

        • 1. Re: ClassCastException deploying Hibernate Search 4.x
          Scott Marlow Master

          Rather than including Hibernate Search jars in your application, I think you need to setup a Hibernate Search module.  I'm not sure if anyone has yet documented how to do that, so it might take some effort (should be mostly documentation).

           

          https://forum.hibernate.org/viewtopic.php?f=9&t=1015297 is similar and also read https://hibernate.onjira.com/browse/HSEARCH-1115.  You could ask if directions are available in the above hibernate forum link.  If not, we could describe some hints for you to get started (come back here and let us know what you find out).

           

          Scott

          • 2. Re: ClassCastException deploying Hibernate Search 4.x
            Tomaz Cerar Master

            Hi,

             

            Seam 2.2 does not work with hibernate 4.x at all.

            That might be couse of your problem, as Seam 2.2 has code uses internal APIs of hibernate 3.

             

            try to upgrade to 2.3 which uses hibernate 4, that might help you with your problem.

             

             

            --

            tomaz

            • 3. Re: ClassCastException deploying Hibernate Search 4.x
              mbickel Newbie

              @Scott: Thanks, I'll have a shot at upgrading jboss' hibernate modules & integrating search.

               

              @Tomaz: yeah, I should've been more clear in stressing "from" seam-2.2 - I'm upgrading TO seam-2.3, that's where I got jboss AS7 and hibernate4 from.

              • 4. Re: ClassCastException deploying Hibernate Search 4.x
                Hardy Ferentschik Novice

                Where exactly did you place jboss-deployment-structure.xml? Are you sure it is picked up correctly? If you look at the log output which version of Hibernate is getting bootstraped (see also
                http://planet.jboss.org/post/some_tips_on_using_hibernate_in_jboss_as_7_0_0_final). Provided the hibernate module is excluded and the classes from within your application are used I would expect this to work. That said, it might also help if you describe how your ear is packaged.

                 

                --Hardy

                • 5. Re: ClassCastException deploying Hibernate Search 4.x
                  mbickel Newbie

                  Thanks for the pointers! Since I've not had the time to re-package Hibernate-4.1 as a module, yet, I've got some more things to try..

                   

                  I've verified that my ear gets deployed with /META-INF/jboss-deployment-structure.xml with this full content:

                   

                   

                  <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
                    <deployment>
                        <exclusions>
                          <module name="org.hibernate" />
                        </exclusions>
                  
                          <dependencies>
                            <module name="javax.faces.api" export="true" />
                            <module name="com.sun.jsf-impl" export="true"/>
                            <module name="org.dom4j" export="true"/>
                            <module name="org.joda.time" export="true"/>
                        </dependencies>
                    </deployment>
                  </jboss-deployment-structure>
                  

                   

                  And I've hunted down the hibernate bootstrap messages, which indeed revealed that Hibernate-4.1 wasn't being loaded:

                   

                  14:30:34,601 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-4) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
                  14:30:34,668 INFO  [org.hibernate.Version] (MSC service thread 1-4) HHH000412: Hibernate Core {4.0.1.Final}
                  14:30:34,671 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-4) HHH000206: hibernate.properties not found
                  14:30:34,675 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-4) HHH000021: Bytecode provider name : javassist
                  

                   

                  Must've missed that on my first try. But the question is now: why aren't the exclusions honoured? I suspect that one of my subdeployments is messing things up and activating implicit module loading. But adding more <exclusions> in seperate <sub-deployment> nodes (I added one node for each of my subdeployments: proj.jar, proj.war and jboss-seam.jar) didn't help, either. Jboss is still loading Hibernate-4.0 from the module path. But why?

                   

                  (I haven't added this, yet,  but this is jboss 7.1.1.Final)

                  • 6. Re: ClassCastException deploying Hibernate Search 4.x
                    Scott Marlow Master

                    Hi Matti,

                     

                    Instead of packaging Hibernate 4.x jars with the application, its easier to apply your changes to AS7/modules/org/hibernate/main (if you want to upgrade the Hibernate version).  We  have more work to do before you can include Hibernate 4 jars with your application as easily as you want to.

                     

                    You will want to setup an AS7/modules/org/hibernate/search folder.  See example changes to the AS7/modules/org/hibernate/main/module.xml file and new Hibernate OGM module.xml here.  The Hibernate ORM classloader needs to see the Hibernate Search module (otherwise Hibernate Search services will not be loaded).

                     

                    The Hibernate search module definition might look something like (someone needs to change the dependencies to match what Search needs):

                     

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                     

                    <module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="search">

                        <resources>

                            <resource-root path="hibernate-search.jar"/>

                        </resources>

                     

                        <dependencies>

                            <module name="javax.api"/>

                            <module name="javax.persistence.api"/>

                            <module name="javax.transaction.api"/>

                            <module name="javax.validation.api"/>

                            <module name="org.dom4j"/>

                            <module name="org.jboss.logging"/>

                            <module name="org.hibernate" export="true"/>

                        </dependencies>

                    </module>

                     

                    And the Hibernate ORM module.xml (as7/modules/org/hibernate/main folder) should look like:

                     

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                     

                    <module xmlns="urn:jboss:module:1.1" name="org.hibernate">

                        <resources>

                            <resource-root path="hibernate-core-4.1.6.Final.jar"/>

                            <resource-root path="hibernate-entitymanager-4.1.6.Final.jar"/>

                            <resource-root path="hibernate-infinispan-4.1.6.Final.jar"/>

                            <!-- Insert resources here -->

                        </resources>

                     

                        <dependencies>

                            <module name="asm.asm"/>

                            <module name="javax.api"/>

                            <module name="javax.persistence.api"/>

                            <module name="javax.transaction.api"/>

                            <module name="javax.validation.api"/>

                            <module name="org.antlr"/>

                            <module name="org.apache.commons.collections"/>

                            <module name="org.dom4j"/>

                            <module name="org.infinispan" optional="true"/>

                            <module name="org.javassist"/>

                            <module name="org.jboss.as.jpa.hibernate" slot="4" optional="true"/>

                            <module name="org.jboss.logging"/>

                            <module name="org.hibernate.envers" services="import" optional="true"/>

                            <module name="org.hibernate" slot="search" services="import"/>

                        <module name="org.hibernate.commons-annotations"/>

                        </dependencies>

                    </module>

                     

                    The important line is the "services=import" that ensures that Hibernate ORM can use the ServiceLoader to see Search services.

                     

                    Scott

                    1 of 1 people found this helpful
                    • 7. Re: ClassCastException deploying Hibernate Search 4.x
                      Hardy Ferentschik Novice

                      We  have more work to do before you can include Hibernate 4 jars with your application as easily as you want to.

                       

                      @Scott, why is it not that easy? Is this not also what "some_tips_on_using_hibernate_in_jboss_as_7_0_0_final" suggests?

                      • 8. Re: ClassCastException deploying Hibernate Search 4.x
                        Scott Marlow Master

                        @Hardy, AS7-5281 has some history.  On AS7 master, the easiest way to accomlish packaging of the Hibernate 4.x jars with the application, would be to include a custom "org.jboss.as.jpa.hibernate:4" adapter that doesn't include the management (for accessing statistics from admin console/cli) dependencies.  Or perhaps we could magically disable the management adapter for the case when Hibernate jars are packaged with the app.  That might be an easier fix.

                        • 9. Re: ClassCastException deploying Hibernate Search 4.x
                          mbickel Newbie

                          I've managed to deploy my ear with the following:

                           

                          AS7/modules/org/hibernate/search/module.xml:

                           

                          <?xml version="1.0" encoding="UTF-8"?>
                          <module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="search">
                              <resources>
                                  <resource-root path="hibernate-search-engine.jar"/>
                              <resource-root path="hibernate-search-analyzers.jar"/>
                              <resource-root path="hibernate-search-orm.jar"/>
                              </resources>
                          
                              <dependencies>
                                  <module name="javax.api"/>
                                  <module name="javax.persistence.api"/>
                                  <module name="javax.transaction.api"/>
                                  <module name="org.jboss.logging"/>
                                  <module name="org.apache.lucene"/>
                                  <module name="org.hibernate" export="true"/>
                              </dependencies>
                          </module>
                          

                           

                          AS7/modules/org/apache/lucene/main/module.xml:

                           

                          <?xml version="1.0" encoding="UTF-8"?>
                          <module xmlns="urn:jboss:module:1.1" name="org.apache.lucene">
                              <resources>
                                  <resource-root path="lucene-core-3.6.1.jar"/>
                                  <resource-root path="lucene-analyzers-3.6.1.jar"/>
                              </resources>
                          </module>
                          

                           

                           

                          And the following jboss-deployment-structure.xml:

                           

                          <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
                            <deployment>
                                  <dependencies>
                                    <module name="javax.faces.api" export="true" />
                                    <module name="com.sun.jsf-impl" export="true"/>
                                    <module name="org.dom4j" export="true"/>
                                    <module name="org.joda.time" export="true"/>
                                    <module name="org.hibernate" slot="search" export="true"/>
                                    <module name="org.apache.lucene" export="true"/>
                                </dependencies>
                            </deployment>
                          </jboss-deployment-structure>
                          

                           

                          I need the direct dep on lucene because I'm defining my own analyzer. If you aren't, you probably don't need this.

                           

                          Hibernate search was made modular, so you probably don't need the analyzers, but I'm using search as a frontend for lucene, so I used the full package.

                          Note that wasn't able to test proper integration yet, as I still need to port my app to Seam-2.3 and all the new goodness I now have available. But seeing my login screen appear was a major milestone

                           

                          Thanks Scott for the pointers and sample xml!

                           

                          Edited to add: after finally being able to start up and test Hibernate Search, it turns out I needed some additional modules, all listed in the pom.xml for hibernate-search. I added:

                           

                          modules/org/apache/avro/main/module.xml

                          <module xmlns="urn:jboss:module:1.1" name="org.apache.avro">
                            <resources>
                                <resource-root path="avro-1.5.1.jar"/>
                              </resources>
                          
                          
                          
                          
                            <dependencies>
                              <module name="org.xerial.snappy"/>
                              <module name="org.codehaus.jackson.jackson-core-asl"/>
                              <module name="org.codehaus.jackson.jackson-mapper-asl"/>
                          
                            </dependencies>
                          
                          
                          
                          </module>
                          
                          

                           

                          modules/org/xerial/snappy/main/module.xml

                          <module xmlns="urn:jboss:module:1.1" name="org.xerial.snappy">
                            <resources>
                              <resource-root path="snappy-java-1.0.4.1.jar"/>
                            </resources>
                          </module>
                          
                          
                          
                          

                           

                          modules/org/hibernate/search/module.xml

                          <module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="search">
                            <resources>
                              <resource-root path="hibernate-search-engine.jar"/>
                              <resource-root path="hibernate-search-analyzers.jar"/>
                              <resource-root path="hibernate-search-orm.jar"/>
                            </resources>
                          
                          
                            <dependencies>
                              <module name="javax.api"/>
                              <module name="javax.persistence.api"/>
                              <module name="javax.transaction.api"/>
                          
                          
                          
                              <module name="org.jboss.logging"/>
                          
                              <module name="org.apache.lucene"/>
                          
                              <module name="org.apache.avro"/>
                          
                              <module name="org.apache.commons.codec"/>
                          
                              <module name="org.apache.commons.io"/>
                          
                              <module name="org.jgroups"/>
                          
                              <module name="org.hibernate" export="true"/>
                            </dependencies>
                          
                          </module>