java - NetBeans 调试期间出现异常

标签 java hibernate gradle netbeans

我有一个具有以下依赖项的 gradle 项目:

    compile "commons-codec:commons-codec:+"
    compile "commons-io:commons-io:+"
    compile "org.apache.poi:poi:+"
    compile "commons-logging:commons-logging:+"
    compile "net.sourceforge.cssparser:cssparser:+"
    compile "net.sourceforge.htmlunit:htmlunit:+"
    compile "net.sourceforge.htmlunit:htmlunit-core-js:+"
    compile "net.sourceforge.htmlunit:neko-htmlunit:+"
    compile "org.apache.commons:commons-lang3:+"
    compile "org.apache.httpcomponents:httpclient:+"
    compile "org.apache.httpcomponents:httpmime:+"
    compile "org.eclipse.jetty.websocket:websocket-client:+"
    compile "xalan:xalan:+"
    compile "org.apache.poi:poi:+"
    compile "org.apache.poi:poi-ooxml:+"
    compile "org.apache.cassandra:cassandra-all:+"
    compile "org.apache.cassandra:cassandra-thrift:+"
   compile "com.whalin:Memcached-Java-Client:+"
   compile "org.hibernate:hibernate-gradle-plugin:+"
   compile "org.hibernate:hibernate-core:+"
   compile "org.hibernate:hibernate-tools:+"
   compile "org.hibernate:hibernate-entitymanager:+"
   compile "org.hibernate:hibernate:+"
   compile "org.hibernate:hibernate-annotations:+"
   compile "mysql:mysql-connector-java:+"
   compile "org.hibernate:ejb3-persistence:+"
   compile "javax:javaee-api:+"
   compile "javax.persistence:persistence-api:+"
   compile "javassist:javassist:+"

我无法使用 NetBeans IDE 在 Debug模式下运行它,当我尝试时,出现以下异常:

18:54:28.174 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property year_end
Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1106)

为什么?

我的问题很独特,因为它与编译无关。我的程序使用以下(gradle)代码可以很好地编译:

task compileJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Applic version 0.9',
            'Implementation-Version': version,
            'Main-Class': 'com.company.runfile'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA' 
}

这会创建正确运行的 jar 文件,但我无法在 NetBeans 中(也在 Intellij IDEA 中)调试相同的应用程序。

最佳答案

stackoverflow 中有很多解决这个问题的答案。

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

更多内容可以查看相关答案:

  1. NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index
  2. java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

关于java - NetBeans 调试期间出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42815359/

相关文章:

java - 如何修复 : No suitable driver found for sqlserver://localhost:1433;DatabaseName=XX

sql - Hibernate setMaxResults() 不适用于 Sybase 数据库查询

gradle - 从 ml-gradle "provider"项目模式启用可重用的 gradle 任务?

java - 在 Gradle Spring Boot 项目中,如何声明仅在本地运行时使用的依赖项?

java - 更高效的 RGB 到 ARGB 转换

java - 多个记录器可以使用相同的处理程序吗?

java - 在 java 中创建后如何修改这个最终的 StringBuffer 值?

hibernate - JPA。 @ManyToOne 相关字段上的 @Column(updatable=false)

spring - 对象引用未保存的 transient 实例 - Spring、JPA Hibernate

android - 多个dex文件-转换为dalvik格式失败