'java.lang.NoSuchMethodError: 'java.lang.String org.hibernate.search.engine.Version.versionString()'

I'm having a problem trying to upgrade hibernate search from v5 to 6.0. I had it working previously but now I'm getting the following error no matter what I do.

Apr 29, 2022 6:50:45 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [fvap] in web application [/ROOT] threw load() exception
java.lang.NoSuchMethodError: 'java.lang.String org.hibernate.search.engine.Version.versionString()'
    at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchIntegrator.integrate(HibernateSearchIntegrator.java:65)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:275)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)

Here are the relevant imports in my pom.xml. I see that the Version is there but I think these is a conflict some where

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <surefire.skipTests>false</surefire.skipTests>
        <lucene.version>8.7.0</lucene.version>
        <hibernate.version>5.4.0.Final</hibernate.version>
        <hibernate.orm.version>5.4.0.Final</hibernate.orm.version>
        <hibernate.annotations.version>5.1.2.Final</hibernate.annotations.version>
        <hibernate-search.version>6.0.9.Final</hibernate-search.version>
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernate.orm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>${hibernate.annotations.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm</artifactId>
            <version>${hibernate-search.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-backend-lucene</artifactId>
            <version>${hibernate-search.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-v5migrationhelper-orm</artifactId>
            <version>${hibernate-search.version}</version>
        </dependency>
<!-- Lucene -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <!-- <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-common</artifactId> <version>${lucene.version}</version> </dependency> -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-highlighter</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>${lucene.version}</version>
        </dependency>


Solution 1:[1]

Most of the time, if you get a NoSuchMethodError, the cause is a JAR in your classpath with the wrong version.

Here, I think you are importing a version of hibernate-search-engine that is not 6.0.9.Final.

The cause is your double dependency to both Hibernate Search 5 and Hibernate Search 6:

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernate.orm.version}</version> <!-- 5.4.0.Final -->
        </dependency>
                <!-- .... -->
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm</artifactId>
            <version>${hibernate-search.version}</version> <!-- 6.0.9.Final -->
        </dependency>

You end up with two copies of org.hibernate.search.engine.Version in your classpath, and here it seems Hibernate Search 6 accessed the copy of the Version class from Hibernate Search 5. Which, obviously, doesn't work.

Anyway... Don't use both Hibernate Search 5 and Hibernate Search 6 in the same application. Remove this from your POM:


<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernate.orm.version}</version>
        </dependency>

Solution 2:[2]

Thanks to @yrodiere for leading me in the right direction. The actual issue was my maven-compiler-plugin and the version of hibernate I was using.

I changed the source and target to 1.8 from 11

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
       <configuration>
          <source>1.8</source>
          <target>1.8</target>
            <useIncrementalCompilation>true</useIncrementalCompilation>
       </configuration>
</plugin>

And change my hibernate version to 5.6.6.Final

<hibernate.version>5.6.6.Final</hibernate.version>

and revert from org.hibernate.orm to org.hibernate

<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>${hibernate.version}</version>
</dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alao