NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index
I've ran into the same problem. The question here is that play-java-jpa artifact (javaJpa key in the build.sbt file) depends on a different version of the 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 brought the newer spec (2.1) and a different factory provider for the entitymanager. Basically you ended up having both jars in the classpath as transitive dependencies.
Edit your build.sbt file like this and it will temporarily fix you problem until play releases a new version of the jpa plugin for the 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
. In previous versions there were some differences in the build files.
java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; inspite of hibernate-jpa-2.1.jar in classpath
Okay, not the best solution but a workaround. Since I was unable to enable weblogic's support for JPA2.1, I replaced Hibernate-core-4.3.5.Final.jar with Hibernate-core-4.2.21.Final.jar (JPA2.1 support was introduced in Hibernate 4.3.0). Not getting that error anymore.
java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
I created a new project and copy all my code in it. I guess my problem happened because of existing 2 version of hibernate-core.jar
, this file hibernate-core-5.2.10.Final.jar
and this hibernate-core-5.2.1.Final.jar
. I deleted extra jar files and copied new lib folder into the new project and it runs successfully.
nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;
I found the work around for this.
I was using WAS 8.5 which provides its own JDK which supports JPA 2.0 . @Table.indexes() method was introduced in JPA 2.1 .
Solution for this
1)Upgrade WAS to 9
2)Instead of using @Table annotation try using xml mapping . I used ClassName.hbm.xml.
Exception in thread main java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
You need to add hibernate-jpa-2.1-api-1.0.0.Final.jar
to the classpath.
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
Table#indexes()
method was added in the version 2.1. So you have an incorrect jar (for an example version 2.0) with the @Table
annotation in the class path. It can be in the default lib
folder of the application server or the web container.
Solution
An incorrect @Table
annotation resides in the persistence-api-1.0.jar
. So it is need to delete this jar from the class path. hibernate-jpa-2.1-api-1.0.0.Final.jar
has all annotations which has persistence-api-1.0.jar
.
Exception java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index, despite using latest version
The problem was solved by letting Netbeans download the libraries itself (By right clicking "Libraries" -> Add Library and choosing Hibernate 4.3 JPA, instead of downloading them from hibernate website.
How to fix javax.persistence.Table.indexes()[Ljavax/persistence/Index?
The first image is the source code of interface Table from javax.persistence.jar
. As you can see there is not the method indexes()
.
The second image is the source code of interface Table from jpa-2.1.jar
. And there method indexes()
is present.
In my opinion, may be you have both jars in your classpath and this create a conflict.
when you call javax.persistence.Table
we don't know if it is the interface from javax.persistence.jar or jpa-2.1.jar.
Look into your classpath and delete the javaxpersistence.jar, and try again.
Related Topics
Should I Initialize Variable Within Constructor or Outside Constructor
Hibernate Annotations - Which Is Better, Field or Property Access
Java Code to Convert Byte to Hexadecimal
Find Java Classes Implementing an Interface
How to Properly Override Clone Method
How to Create a Jar with External Libraries Included in Eclipse
Find a Line in a File and Remove It
Java: Define Terms Initialization, Declaration and Assignment
How Will Java Lambda Functions Be Compiled
Calling a Subclass Method from Superclass
Java and Gui - Where Do Actionlisteners Belong According to MVC Pattern
Java Comparison with == of Two Strings Is False
When and How to Use a Threadlocal Variable
Java 8 Iterable.Foreach() VS Foreach Loop
What Is Web-Inf Used for in a Java Ee Web Application
What Is the Easiest/Best/Most Correct Way to Iterate Through the Characters of a String in Java
How to Catch Multiple Java Exceptions in the Same Catch Clause