javax.persistence.Table.indexes()[Ljavax/persistence/Index 中的 NoSuchMethodError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20734540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index
提问by musubi
I have a Play Framework application and I wasusing Hibernate 4.2.5.Final (which is retrieved via the Maven dependency manager). I decided to upgrade to Hibernate 4.3.0.Final, recompile my application successfully, and ran it.
我有一个游戏框架应用程序,我是使用Hibernate 4.2.5.Final(这是通过Maven的依赖管理检索)。我决定升级到 Hibernate 4.3.0.Final,成功重新编译我的应用程序并运行它。
I got the exception below, and haven't been able to figure out why. I downgraded back to 4.2.5 and this issue did not occur. I then, tried upgrading Hibernate with each Final release after 4.2.5. That is, I went from 4.2.5.Final to 4.2.6.Final, to 4.2.7.Final, to 4.2.8.Final and then to 4.3.Final. The issue does not occur until I upgrade to 4.3.0.Final.
我在下面得到了例外,并且无法弄清楚原因。我降级回 4.2.5 并没有出现这个问题。然后,我尝试在 4.2.5 之后的每个最终版本中升级 Hibernate。也就是说,我从 4.2.5.Final 到 4.2.6.Final,到 4.2.7.Final,到 4.2.8.Final,然后到 4.3.Final。在我升级到 4.3.0.Final 之前不会出现此问题。
Java version information
Java版本信息
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 exception:
和例外:
play.api.UnexpectedException: Unexpected exception[NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;]
at play.core.ReloadableApplication$$anonfun$get$$anonfun$apply$$anonfun.apply(ApplicationProvider.scala:152) ~[play_2.10.jar:2.2.1]
at play.core.ReloadableApplication$$anonfun$get$$anonfun$apply$$anonfun.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$$anonfun$apply.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.1]
at play.core.ReloadableApplication$$anonfun$get$$anonfun$apply.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]
采纳答案by hcura
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")
.
我遇到了同样的问题。这里的问题是 play-java-jpa 工件(build.sbt 文件中的 javaJpa 键)取决于规范的不同版本(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.
当您添加 hibernate-entitymanager 4.3 时,这带来了更新的规范 (2.1) 和实体管理器的不同工厂提供程序。基本上,您最终将类路径中的两个 jar 作为传递依赖项。
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.
像这样编辑你的 build.sbt 文件,它会暂时解决你的问题,直到 play 为较新的 api 依赖项发布新版本的 jpa 插件。
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.
这是为了play 2.2.x
. 在以前的版本中,构建文件存在一些差异。
回答by JB Nizet
Hibernate 4.3 is the first version to implement the JPA 2.1 spec (part of Java EE 7). And it's thus expecting the JPA 2.1 library in the classpath, not the JPA 2.0 library. That's why you get this exception: Table.indexes() is a new attribute of Table, introduced in JPA 2.1
Hibernate 4.3 是第一个实现 JPA 2.1 规范(Java EE 7 的一部分)的版本。因此,它期望在类路径中使用 JPA 2.1 库,而不是 JPA 2.0 库。这就是为什么您会收到此异常的原因:Table.indexes() 是 Table 的新属性,在 JPA 2.1 中引入
回答by Xelian
You probablly have 2 different versions of hibernate-jpa-api on the classpath. To check that run:
您可能在类路径上有 2 个不同版本的 hibernate-jpa-api。要检查该运行:
mvn dependency:tree >dep.txt
Then search if there are hibernate-jpa-2.0-api and hibernate-jpa-2.1-api. And exclude the excess one.
然后搜索是否有hibernate-jpa-2.0-api和hibernate-jpa-2.1-api。并排除多余的。
回答by sinihong
I could solve the issue simply by replacing the JPA api jar file which is located jboss7/modules/javax/persistence/api/main with 'hibernate-jpa-2.1-api'. also with updating module.xml in the directory.
我可以通过将位于 jboss7/modules/javax/persistence/api/main 的 JPA api jar 文件替换为“hibernate-jpa-2.1-api”来解决这个问题。还更新目录中的module.xml。
回答by Marceloni Lima
Error: java.lang.NoSuchMethodError: javax.persistence.JoinTable.indexes()[Ljavax/persistence/Index;
错误:java.lang.NoSuchMethodError:javax.persistence.JoinTable.indexes()[Ljavax/persistence/Index;
The only thing that solved my problem was removing 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>
解决我的问题的唯一方法是删除 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 for:
并将其替换为:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
Hope it helps someone.
希望它可以帮助某人。
回答by Herbert Rausch
I update my Hibernate JPA to 2.1 and It works.
我将我的 Hibernate JPA 更新到 2.1 并且它有效。
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
回答by Damitha Dayananda
i have experienced same issue in my spring boot application. after removing manually javax.persistance.jar file from lib folder. issue was fixed. in pom.xml file i have remained following dependency only
我在 Spring Boot 应用程序中遇到了同样的问题。从 lib 文件夹中手动删除 javax.persistance.jar 文件后。问题已修复。在 pom.xml 文件中,我只遵循依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
回答by Praveen
I had the same issue, I fixed it by using org.hibernate.annotations.Table
annotation instead of javax.persistence.Table
in the Entity class.
我遇到了同样的问题,我通过使用org.hibernate.annotations.Table
注释而不是javax.persistence.Table
在实体类中来修复它。
import javax.persistence.Entity;
import org.hibernate.annotations.Table;
@Entity
@Table(appliesTo = "my_table")
public class MyTable{
//and rest of the code
回答by abitcode
There are multiple JPA providers in your classpath. Or atleast in your Application server lib folder.
您的类路径中有多个 JPA 提供程序。或者至少在您的应用程序服务器 lib 文件夹中。
If you are using Maven Check for dependencies using command mentioned here https://stackoverflow.com/a/47474708/3333878
如果您使用 Maven 检查依赖项使用这里提到的命令https://stackoverflow.com/a/47474708/3333878
Then fix by removing/excluding unwanted dependency.
然后通过删除/排除不需要的依赖项来修复。
If you just have one dependecy in your classpath, then the application server's class loader might be the issue.
如果您的类路径中只有一个依赖项,那么应用程序服务器的类加载器可能是问题所在。
As JavaEE application servers like Websphere, Wildfly, Tomee etc., have their own implementations of JPA and other EE Standards, The Class loader might load it's own implementation instead of picking from your classpath in WAR/EAR file.
由于 Websphere、Wildfly、Tomee 等 JavaEE 应用服务器有自己的 JPA 和其他 EE 标准实现,类加载器可能会加载它自己的实现,而不是从 WAR/EAR 文件中的类路径中选择。
To avoid this, you can try below steps.
为避免这种情况,您可以尝试以下步骤。
- Removing the offending jar in Application Servers library path. Proceed with Caution, as it might break other hosted applications.
- 删除应用服务器库路径中的有问题的 jar。请谨慎操作,因为它可能会破坏其他托管应用程序。
In Tomee 1.7.5 Plume/ Web it will have bundled eclipselink-2.4.2
in the lib
folder using JPA 2.0, but I had to use JPA 2.1 from org.hibernate:hibernate-core:5.1.17
, so removed the eclipselink jar and added all related/ transitive dependencies from hibernate core.
在 Tomee 1.7.5 Plume/Web 中,它将使用 JPA 2.0捆绑eclipselink-2.4.2
在lib
文件夹中,但我必须使用org.hibernate:hibernate-core:5.1.17
来自 .
Add a shared library. and manually add jars to the app server's path. Websphere has this option.
In Websphere, execution of class loader can be changed. so making it the application server's classpath to load last i.e, parent last and having your path load first. Can solve this.
添加共享库。并手动将 jars 添加到应用程序服务器的路径。Websphere 有这个选项。
在 Websphere 中,可以更改类加载器的执行。所以使它成为应用程序服务器的类路径最后加载,即父级最后并首先加载您的路径。可以解决这个。
Check if your appserver has above features, before proceeding with first point.
在继续第一点之前,请检查您的应用服务器是否具有上述功能。
Ibm websphere References :
IBM WebSphere 参考资料: