【问题标题】:Exception during debug in NetBeans在 NetBeans 中调试期间出现异常
【发布时间】:2017-08-06 12:32:19
【问题描述】:

我有一个具有以下依赖项的 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 在调试模式下运行它,当我尝试时,出现以下异常:

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)中调试相同的应用程序。

【问题讨论】:

标签: java hibernate gradle netbeans


【解决方案1】:

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

JB Nizet 已经挖掘了这个问题,并告诉了根本原因和解决过程如下:

Hibernate 4.3 是第一个实现 JPA 2.1 规范的版本(部分 Java EE 7)。因此它期待 JPA 2.1 库在 类路径,而不是 JPA 2.0 库。这就是你得到这个异常的原因: Table.indexes() 是 Table 的一个新属性,在 JPA 2.1 中引入

更多可以查看相关答案:

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

【讨论】:

  • 为什么编译得这么好?我仅在调试尝试期间遇到异常。并且应用程序运行良好,无需在 IDE 之外进行调试。可能这是某种 gradle 问题。
  • @Catherine 调试时间异常实际上是由于另一个原因而发生的。可能有多个线程正在等待回复。当收到回复包时,在接收管理器中执行 notifyAll(),这将让一个线程检查回复包队列。如果回复不是针对正在等待的线程,它会再次进入等待状态,但不会通知允许另一个等待线程检查回复队列。因此,就会出现这个问题。
  • 连接到目标VM,地址:'127.0.0.1:59507',传输:'socket' Mar 20, 2017 6:59:23 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate核心 {5.2.9.Final} 2017 年 3 月 20 日下午 6:59:23 org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found 与目标 VM 断开连接,地址:'127.0.0.1: 59507',传输:'socket' 2017 年 3 月 20 日下午 6:59:24 实体。CarScrapperHibernateUtil 严重:null java.lang.NoSuchMethodError:
  • 在debug中运行失败,但在没有debug的情况下运行良好。它在休眠初始化阶段“ sessionFactory = new Configuration().configure().buildSessionFactory();”失败现在是不同的异常:java.lang.NoSuchMethodError: org.hibernate.annotations.common.reflection.java.JavaReflectionManager.setMetadataProvider(Lorg/hibernate/annotations/common/reflection/MetadataProvider;)VI 现在不知道它是怎么发生的,我已更改 gradle 依赖项
  • @Catherine 你用的是哪个休眠版本?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 2021-11-03
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-30
相关资源
最近更新 更多