当前位置: 首页 > 知识库问答 >
问题:

实现Hibernate搜索时出现 Java 链接错误

蓝飞
2023-03-14

我把所有必需的jar放在类路径中,但仍然得到以下错误:

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;

>

  • 类路径中的Jars:

    1. 蚂蚁.jar
    2. 同学-1.3.0.jar
    3. 共享资源集合-3.2.1.jar
    4. dom4j-1.6.1.jar
    5. 冬眠3.jar
    6. Hibernate注释.jar
    7. Hibernate实体管理器.jar
    8. Hibernate-搜索引擎-5.6.0.最终.jar
    9. Hibernate搜索 orm-5.6.0.最终.jar
    10. 3.20.0-GA.jar
    11. jboss-log-3.3.0.final.jar
    12. 甲苯芯-5.5.2.jar
    13. 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个答案

    杨成礼
    2023-03-14

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

    你的Hibernate ORM版本已经过时了。你的Spring也一样。你将无法使用Hibernate Search 5.6.0.Final。如果你想让它们一起工作,你应该选择彼此兼容的版本。而且我会推荐你使用Spring的最新稳定版和兼容Hibernate Search 5.6.0.Final的Hibernate ORM的最新版本。

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

     类似资料:
    • 我试图为hibernate OGM mongo DB应用程序添加hibernate搜索支持。当我尝试使用行重新生成索引时,经常会出现以下异常。 HSearch000058:HSearch000116:MassIndexer操作过程中出现意外错误java.lang.NosuchMethoderror:org.hibernate.search.engine.spi.documentBuilderInd

    • Virtuoso 37000错误SP030:SPARQL编译器,第21行:“_new_south_wales”之前“,”处的语法错误SPARQL查询:#output-format:application/SPARQL-results+JSON define输入:default-graph-uri PREFIX owl:PREFIX xsd:PREFIX rdfs:PREFIX rdfs:PREFI

    • 我想使用executeQuery mongodb驱动程序php搜索_id。 这是我的用户集合的文档结构 而我的php代码是 当我运行它时,我发现以下错误 PHP致命错误:未捕获异常“MongoDB\Driver\exception\ConnectionException”,在/测试中显示消息“未知运算符:$id”。php:27堆栈跟踪:0/测试。php(27):MongoDB\Driver\Man

    • 请帮帮我,我对这个很陌生。提前谢了。

    • 问题内容: 我正在编写一个使用二进制搜索树存储数据的程序。在以前的程序中(无关),我能够使用Java SE6随附的实现来实现链表。二进制搜索树是否有类似的东西,还是我需要“从头开始”? 问题答案: 您可以使用。被实现为一棵红黑树,这是一个自平衡二进制搜索树。

    • 我正在使用Hibernate Search和Lucene在文档数据库的内容字段上进行全文搜索。我有一个搜索文本框,正在进行用户查询。我已经修复了搜索短语匹配基于搜索。我想使用搜索的组合。为了解释我的观点,假设用户想搜索“美国”。如果我使用基于短语的搜索,它会给我查询上的每一次出现,并忽略“联合”和“国家”的个别出现。如果我进行字段匹配搜索,它将获取包含单个查询词的所有结果。我的问题是,是否有任何直