如何修复“NoSuchMethodError ParameterMetadataImpl <init>

How to fix "NoSuchMethodError ParameterMetadataImpl <init>

当我 运行 在代码中显示 searchByKeywords 方法时,我收到一条关于 org.hibernate.query.internal.ParameterMetadataImpl:

缺少构造函数的错误消息
java.lang.NoSuchMethodError: org.hibernate.query.internal.ParameterMetadataImpl.<init>([Lorg/hibernate/engine/query/spi/OrdinalParameterDescriptor;Ljava/util/Map;)V
at org.hibernate.search.impl.FullTextSessionImpl.createFullTextQuery(FullTextSessionImpl.java:88) ~[hibernate-search-orm-5.9.2.Final.jar:5.9.2.Final]
at org.hibernate.search.impl.FullTextSessionImpl.createFullTextQuery(FullTextSessionImpl.java:78) ~[hibernate-search-orm-5.9.2.Final.jar:5.9.2.Final]
at org.hibernate.search.impl.FullTextSessionImpl.createFullTextQuery(FullTextSessionImpl.java:52) ~[hibernate-search-orm-5.9.2.Final.jar:5.9.2.Final]
at de.estructor.portal.data.jpa.repo.training.TrainingRepoSearchImpl.searchByKeywords(TrainingRepoSearchImpl.java:50) ~[classes/:na]

当我要求 IDE 打开文件时,我可以看到构造函数存在

public ParameterMetadataImpl(
    Map<Integer,OrdinalParameterDescriptor> ordinalDescriptorMap,
    Map<String, NamedParameterDescriptor> namedDescriptorMap) {

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.estructor</groupId>
    <artifactId>data</artifactId>
    <version>0.0.1</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-data</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.javafaker</groupId>
            <artifactId>javafaker</artifactId>
            <version>0.16</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-data-rest</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.skyscreamer</groupId>
            <artifactId>jsonassert</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <version>1.5.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search</artifactId>
            <version>5.9.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-elasticsearch</artifactId>
            <version>5.9.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-envers</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-resource-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>auth0</artifactId>
            <version>1.9.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

这是我的代码,它会在我使用休眠搜索的方式出现问题时产生错误:

public List<Training> searchByKeywords(final String[] keywords) {
    FullTextEntityManager fullTextEm = Search.getFullTextEntityManager(this.entityManager);
    QueryBuilder qb = fullTextEm.getSearchFactory().buildQueryBuilder().forEntity(Training.class).get();

    List<Query> queryList = new LinkedList<Query>();
    for (String keyword : keywords) {
        keyword = keyword.trim().toLowerCase();
        queryList.add(qb.keyword().onFields(searchFields).matching(keyword).createQuery());
    }

    BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
    for (Query q : queryList) {
        booleanQuery.add(q, Occur.MUST);
    }

    FullTextQuery fullTextQuery = fullTextEm.createFullTextQuery(booleanQuery.build(), Training.class);

    return (List<Training>) fullTextQuery.getResultList();
}

您使用的 Hibernate ORM 和 Hibernate Search 版本不兼容。

在此处查看我们的兼容性矩阵:http://hibernate.org/search/releases/#compatibility-matrix .

您的 Spring Boot 版本正在使用 ORM 5。3.x 因此您应该使用 Search 5。10.x(最新版本是 5.10。5.Final)。