Home  >  Article  >  Java  >  Why Does Upgrading Hibernate from 4.2.5.Final to 4.3.0.Final Cause a `NoSuchMethodError` in `javax.persistence.Table.indexes()`?

Why Does Upgrading Hibernate from 4.2.5.Final to 4.3.0.Final Cause a `NoSuchMethodError` in `javax.persistence.Table.indexes()`?

Barbara Streisand
Barbara StreisandOriginal
2024-11-24 01:54:12987browse

Why Does Upgrading Hibernate from 4.2.5.Final to 4.3.0.Final Cause a `NoSuchMethodError` in `javax.persistence.Table.indexes()`?

NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index

Question:

When upgrading from Hibernate 4.2.5.Final to 4.3.0.Final in a Play Framework application, an exception occurs:

java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

Answer:

The issue arises due to a conflict between different versions of the Java Persistence API (JPA) specification dependencies in the application's classpath. Specifically, the Play Framework JPA plugin includes a dependency on the JPA 2.0 specification, while Hibernate 4.3.0.Final requires the newer JPA 2.1 specification.

To resolve this issue, exclude the JPA 2.0 specification dependency from the build.sbt file and replace it with the following dependency on the JPA 2.1 specification:

"org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Final"

For Play 2.2.x, edit the build.sbt file as follows:

libraryDependencies ++= Seq(
  javaJdbc,
  javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
  "org.hibernate" % "hibernate-entitymanager" % "4.3.0.Final"
)

By excluding the JPA 2.0 dependency and including the JPA 2.1 dependency, you ensure that the correct version of the JPA specification is used, resolving the NoSuchMethodError exception.

The above is the detailed content of Why Does Upgrading Hibernate from 4.2.5.Final to 4.3.0.Final Cause a `NoSuchMethodError` in `javax.persistence.Table.indexes()`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn