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

I’m having a problem trying to upgrade hibernate search. I had ti 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 my pom.xml imports

<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>

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 Version 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>

Seems like this question was copied from Stackoverflow: java.lang.NoSuchMethodError: 'java.lang.String org.hibernate.search.engine.Version.versionString()' - Stack Overflow

Closing, continuing the discussion (if any) on Stackoverflow.