我正在使用 Spring Boot v
3.3.1
和 Java 17 我正在尝试使用下面的 Hibernate Search 依赖项来使用 @Indexed 注释和 @Field 注释、实体类中的 TermVector 以及其他搜索相关方法。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.11.12.Final</version>
</dependency>
添加上述依赖项后,我收到以下错误 -
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.hibernate.search.cfg.impl.SearchConfigurationFromHibernateCore.<init>(SearchConfigurationFromHibernateCore.java:96)
The following method did not exist:
'org.hibernate.MultiTenancyStrategy org.hibernate.boot.spi.SessionFactoryOptions.getMultiTenancyStrategy()'
The calling method's class, org.hibernate.search.cfg.impl.SearchConfigurationFromHibernateCore, was loaded from the following location:
jar:file:/C:/Users/Dell/.m2/repository/org/hibernate/hibernate-search-orm/5.11.12.Final/hibernate-search-orm-5.11.12.Final.jar!/org/hibernate/search/cfg/impl/SearchConfigurationFromHibernateCore.class
The called method's class, org.hibernate.boot.spi.SessionFactoryOptions, is available from the following locations:
jar:file:/C:/Users/Dell/.m2/repository/org/hibernate/orm/hibernate-core/6.5.2.Final/hibernate-core-6.5.2.Final.jar!/org/hibernate/boot/spi/SessionFactoryOptions.class
jar:file:/C:/Users/Dell/.m2/repository/org/hibernate/hibernate-core/5.4.33.Final/hibernate-core-5.4.33.Final.jar!/org/hibernate/boot/spi/SessionFactoryOptions.class
The called method's class hierarchy was loaded from the following locations:
org.hibernate.boot.spi.SessionFactoryOptions: file:/C:/Users/Dell/.m2/repository/org/hibernate/orm/hibernate-core/6.5.2.Final/hibernate-core-6.5.2.Final.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.hibernate.search.cfg.impl.SearchConfigurationFromHibernateCore and org.hibernate.boot.spi.SessionFactoryOptions
下面是我的Pom.xml文件依赖项
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.11.12.Final</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
</dependencies>
我尝试了很多其他人提供的解决方案,但到目前为止都没有效果。有没有更好的方法来调用EntityManager等搜索相关方法?
我建议查看入门指南https://docs.jboss.org/hibernate/search/7.2/getting-started/orm/en-US/html_single/#gettingstarted-dependency,其中使用BOM 的解释是为了简化依赖管理。
那么您至少需要使用 Hibernate Search 6.2(带有 -orm6 工件)或当前最新的 7.2。请参阅兼容性矩阵以匹配您的 ORM 版本 https://hibernate.org/search/releases/#compatibility-matrix Spring Boot 使用 Hibernate ORM 6.x 系列,因此它无法与 Hibernate Search 5.x 一起使用...