Home > Java > javaTutorial > body text

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

Barbara Streisand
Release: 2024-11-24 01:54:12
Original
983 people have browsed it

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;
Copy after login

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"
Copy after login

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"
)
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template