gpt4 book ai didi

实现 Hibernate Search 时出现 Java 链接错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:51:16 25 4
gpt4 key购买 nike

我将所有需要的 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;
  • 类路径中的 jar :

    1. antlr.jar
    2. classmate-1.3.0.jar
    3. commons-collections-3.2.1.jar
    4. dom4j-1.6.1.jar
    5. hibernate3.jar
    6. hibernate-annotations.jar
    7. hibernate-entitymanager.jar
    8. hibernate-search-engine-5.6.0.Final.jar
    9. hibernate-search-orm-5.6.0.Final.jar
    10. javassist-3.20.0-GA.jar
    11. jboss-logging-3.3.0.Final.jar
    12. lucene-core-5.5.2.jar
    13. xml-apis-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>

提前致谢!

最佳答案

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

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

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

关于实现 Hibernate Search 时出现 Java 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41971973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com