javax.persistence.Table.indexes()[Ljavax/persistence/Index 中的 NoSuchMethodError [英] NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index

查看:37
本文介绍了javax.persistence.Table.indexes()[Ljavax/persistence/Index 中的 NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Play Framework 应用程序,我曾经使用 Hibernate 4.2.5.Final(通过 Maven 依赖管理器检索).我决定升级到 Hibernate 4.3.0.Final,成功重新编译我的应用程序,并运行它.

I have a Play Framework application and I was using 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.

我收到了以下异常,但一直无法弄清楚原因.我降级回 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 后才会出现此问题.

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.

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)

和例外:

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]

推荐答案

我遇到了同样的问题.这里的问题是 play-java-jpa 工件(build.sbt 文件中的 javaJpa 键)取决于规范的不同版本(版本 2.0 -> "org.hibernate.javax.persistence" % "hibernate-jpa-2.0-api" % "1.0.1.Final").

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").

当您添加 hibernate-entitymanager 4.3 时,这带来了更新的规范 (2.1) 和不同的实体管理器工厂提供程序.基本上,您最终将类路径中的两个 jar 作为传递依赖项.

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.

像这样编辑你的 build.sbt 文件,它会暂时解决你的问题,直到 play 为较新的 api 依赖项发布新版本的 jpa 插件.

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"
)

这是用于play 2.2.x.在以前的版本中,构建文件存在一些差异.

This is for play 2.2.x. In previous versions there were some differences in the build files.

这篇关于javax.persistence.Table.indexes()[Ljavax/persistence/Index 中的 NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆