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

I have a Play Framework application and I used Hibernate 4.2.5.Final (which is retrieved through the Maven dependency manager). I decided to switch to Hibernate 4.3.0.Final, successfully recompile the application and run it.

I got the exception below and could not understand why. I dropped to 4.2.5 and this problem did not occur. Then I tried to update Hibernate with every final release after 4.2.5. That is, I went from 4.2.5. Final to 4.2.6. Final, up to 4.2.7. Final, to 4.2.8.Final, and then to 4.3.Final. The problem does not occur until I go to 4.3.0.Final.

Java Version Information

java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode) 

And an exception :

 play.api.UnexpectedException: Unexpected exception[NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:152) ~[play_2.10.jar:2.2.1] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.1] at scala.Option.map(Option.scala:145) ~[scala-library.jar:na] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.1] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.1] at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na] Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) ~[hibernate-core-4.3.0.Final.jar:4.3.0.Final] 
+74
java hibernate jpa
Dec 22 '13 at 22:06
source share
6 answers

I ran into the same problem. The question here is that play-java-jpa artifact (the javaJpa key in the build.sbt file) depends on another version of spec (version 2.0 -> "org.hibernate.javax.persistence" % "hibernate-jpa-2.0-api" % "1.0.1.Final") .

When you added hibernate-entitymanager 4.3, this led to the newer specification (2.1) and another factory provider for entitymanager. Basically, you have both bans in the class path as transitive dependencies.

Modify the build.sbt file this way and it will temporarily fix your problem until playback releases a new version of the jpa plugin for a newer api dependency.

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

This is for play 2.2.x There were some differences in build files in previous versions.

+72
Dec 27 '13 at 12:37
source share

Hibernate 4.3 is the first version to implement the JPA 2.1 specification (part of Java EE 7). And so he expects the JPA 2.1 library in the classpath, not the JPA 2.0 library. That's why you get this exception: Table.indexes () is the new table attribute introduced in JPA 2.1

+62
Dec 22 '13 at 22:19
source share

You probably have two different versions of hibernate-jpa-api in the classpath. To check this run:

 mvn dependency:tree >dep.txt 

Then search if there is hibernate-jpa-2.0-api and hibernate-jpa-2.1-api. And exclude the excess.

+11
Jan 18 '15 at 13:34
source share

I upgrade JPY for Hibernate to 2.1 and it works.

 <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> </dependency> 
+8
Jul 02 '16 at 22:27
source share

I could solve the problem by simply replacing the JPA jar api file that contains jboss7 / modules / javax / persistence / api / main with 'hibernate-jpa-2.1-api'. also with updating module.xml in the directory.

+6
Jan 20 '15 at 20:47
source share

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

The only thing that resolved my problem was to remove the following dependency in pom.xml: <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> </dependency>

And replace it with:

 <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> </dependency> 

Hope this helps someone.

0
Jun 19 '16 at 18:27
source share



All Articles