实现Hibernate Search时出现Java Linkage错误

时间:2017-02-01 04:36:34

标签: java spring hibernate jboss hibernate-search

我将所有必需的jar放在class-path中,但仍然出现以下错误:

Failed to define class org.hibernate.search.impl.FullTextSessionImpl in Module "com.cirq:main" from local module loader @7a08c0a3 (roots: /home/jboss/modules): java.lang.LinkageError: Failed to link org/hibernate/search/impl/FullTextSessionImpl (Module "com.cirq:main" from local module loader @7a08c0a3 (roots: /home/jboss/modules))
        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
        at org.jboss.modules.Module.loadModuleClass(Module.java:517)
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
        at org.hibernate.search.impl.ImplementationFactory.createFullTextSession(ImplementationFactory.java:34) [hibernate-search-orm-5.6.0.Final.jar:5.6.0.Final]
        at org.hibernate.search.Search.getFullTextSession(Search.java:44) [hibernate-search-orm-5.6.0.Final.jar:5.6.0.Final]
        at com.cirq.dao.implementation.UserInformationSearchDAO$2.doInHibernate(UserInformationSearchDAO.java:72) [classes:]
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367) [spring.jar:2.0.2]
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:333) [spring.jar:2.0.2]
        at com.cirq.dao.implementation.UserInformationSearchDAO.searchForUserInfo(UserInformationSearchDAO.java:58) [classes:]
        at com.cirq.controller.devicecontroller.UserInformationSearchLucene.handleRequest(UserInformationSearchLucene.java:63) [classes:]
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45) [spring.jar:2.0.2]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820) [spring.jar:2.0.2]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755) [spring.jar:2.0.2]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396) [spring.jar:2.0.2]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350) [spring.jar:2.0.2]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
        at com.cirq.controller.devicecontroller.DeviceEndPoint.handleRequest(DeviceEndPoint.java:73) [classes:]
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45) [spring.jar:2.0.2]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820) [spring.jar:2.0.2]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755) [spring.jar:2.0.2]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396) [spring.jar:2.0.2]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350) [spring.jar:2.0.2]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:205) [cors-filter-1.3.2.jar:]
        at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:266) [cors-filter-1.3.2.jar:]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_111]
Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/spi/SessionImplementor
        at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_111]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:803) [rt.jar:1.7.0_111]
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_111]
        at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
        ... 54 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.spi.SessionImplementor from [Module "com.cirq:main" from local module loader @7a08c0a3 (roots: /home/jboss/modules)]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
        ... 59 more

这是我的代码段:

//错误在第1行。

       FullTextSession fullTextSession1 = Search.getFullTextSession(session);

            QueryBuilder qb = fullTextSession1.getSearchFactory()
                    .buildQueryBuilder().forEntity(Book.class).get();

            org.apache.lucene.search.Query query = qb.keyword().onFields("mobileno","fname")
                    .matching(searchText).createQuery();

            org.hibernate.Query hibQuery = fullTextSession1.createFullTextQuery(query, UserInformation.class);

            List results = hibQuery.list();
            System.out.println("Result Ser Size " +results.size());
            return results;
  • 类路径中的jar:

    1. antlr.jar
    2. 同学-1.3.0.jar
    3. 公地集合-3.2.1.jar
    4. DOM4J-1.6.1.jar
    5. hibernate.jar文件
    6. 冬眠-annotations.jar
    7. 冬眠-entitymanager.jar
    8. 冬眠-搜索引擎-5.6.0.Final.jar
    9. 冬眠-搜索ORM-5.6.0.Final.jar
    10. 了Javassist-3.20.0-GA.jar
    11. 的JBoss-测井3.3.0.Final.jar
    12. lucene的核 - 5.5.2.jar
    13. XML的API-1.3.03.jar

使用的Spring版本:2.0和使用的Hibernate版本:3.0

Spring Bean Congif文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


    <!-- ========================== DATASOURCE CONFIGURATION =============================== -->
    <!-- OLD comment -->
    <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/onlineadmissions"/>
        <property name="username" value="root"/>
        <property name="password" value="iamme1234"/>
        </bean> -->

    <bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean"
        destroy-method="close">
        <property name="jndiName" value="java:/cirq" />
    </bean>
    <!-- =========================== HIBERNATE IMPLEMENTATIONS ========================== -->

    <bean id="dbSessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="configLocation">
            <value>.\WEB-INF\hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.bytecode.provider">javassist</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.cache.use_second_level_cache">false</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.connection.characterEncoding">utf8</prop>

                <prop key="hibernate.search.default.directory_provider">
                    org.hibernate.search.store.impl.FSDirectoryProvider</prop>
                <prop key="hibernate.search.default.indexBase">
                    D:\IntelliJWorkspace\cirqfinedine\index</prop>
            </props>
        </property>

    </bean>


    <bean id="hibernateTemplate"
        class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="dbSessionFactory" />
        </property>
    </bean>

    <bean id="cachedHibernateTemplate"
        class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="dbSessionFactory" />
        </property>
        <property name="cacheQueries">
            <value>true</value>
        </property>
    </bean>


    <!-- =========================== DAO IMPLEMENTATIONS ========================== -->


    <bean id="userInformationSearchDAO"
          class="com.cirq.dao.implementation.UserInformationSearchDAO">
        <property name="hibernateTemplate">
            <ref bean="hibernateTemplate" />
        </property>
    </bean>

Hibernate配置文件:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="com.cirq.model.CashDetails" />
        <mapping class="com.cirq.model.Category" />
        <mapping class="com.cirq.model.Customers" />
        <mapping class="com.cirq.model.MenuItems" />
        <mapping class="com.cirq.model.OrderDetails" />
        <mapping class="com.cirq.model.Orders" />
</session-factory>

</hibernate-configuration>

Persistance.xml文件:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
   version="1.0">

<!--  This mapping file provided for the hibernateTool facility  -->
   <persistence-unit name="kuyke">

       <!-- The provider only needs to be set if you use several JPA providers
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
        -->
       <!-- This is required to be spec compliant, Hibernate however supports
            auto-detection even in JSE.-->
       <class>com.cirq.model.CashDetails</class>
       <class>com.cirq.model.Category</class>
       <class>com.cirq.model.Customers</class>
       <class>com.cirq.model.MenuItems</class>
       <class>com.cirq.model.OrderDetails</class>
       <class>com.cirq.model.Orders</class>

      <properties>
          <!-- Scan for annotated classes and Hibernate mapping XML files -->
          <property name="hibernate.archive.autodetection" value="class, hbm"/>

        <!-- Uncomment For DEV-->
          <property name="hibernate.connection.driver_class"
                    value="com.mysql.jdbc.Driver"/>

          <property name="hibernate.connection.url"
                    value="jdbc:mysql://localhost:3306/cirq?autoReconnect=true"/>

           <property name="hibernate.connection.username"
                    value="smartideas"/>
          <property name="hibernate.connection.password"
                    value="smart543ideas"/>

          <property name="hibernate.c3p0.min_size"
                    value="5"/>
          <property name="hibernate.c3p0.max_size"
                    value="20"/>
          <property name="hibernate.c3p0.timeout"
                    value="300"/>
          <property name="hibernate.c3p0.max_statements"
                    value="50"/>
          <property name="hibernate.c3p0.idle_test_period"
                    value="3000"/>

          <property name="hibernate.dialect"
                    value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
          <property name="hibernate.cache.use_query_cache" value="true"/>


      <!--     Enable Hibernate's automatic session context management
          <property name="current_session_context_class" value="thread"/>

           Disable the second-level cache
          <property name="cache.provider_class" value="org.hibernate.cache.internal.NoCacheProvider"/>-->

          <!-- Store index in memory, so no index cleanup required after tests -->
          <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.impl.RAMDirectoryProvider"/>


          <!-- Would set this in production application. Index stored on disk. -->
          <!-- <property name="hibernate.search.default.directory_provider">
              org.hibernate.search.store.impl.FSDirectoryProvider
          </property>
          <property name="hibernate.search.default.indexBase">c:/temp/lucene/indexes</property>
          -->

          <!-- Define Hibernate entity mappings. Standard Hibernate stuff - not specific
              to Hibernate Search. -->


      </properties>
   </persistence-unit>

</persistence>

提前致谢!

1 个答案:

答案 0 :(得分:1)

错误消息告诉您使用的组件版本彼此不兼容。

你的Hibernate ORM版本已经过时了。您的Spring版本也是如此。您将无法使用Hibernate Search 5.6.0.Final。如果您希望它们一起工作,您应该选择彼此兼容的版本。我建议你使用最新的稳定版本的Spring和最新版本的Hibernate ORM兼容Hibernate Search 5.6.0.Final。

使用Hibernate Search 5.6.0.Final,您应该使用最新的Hibernate ORM 5.1.x(我写这篇文章时的5.1.4.Final)。