1

I have a gradle project with following dependencies:

    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:+"

I can't run it in debug mode using NetBeans IDE, when I try, I got following exception:

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)

Why?

My question is unique because it is not about compilation. My program compiles well with following (gradle) code :

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' 
}

This creates jar file which run properly, but I can not debug the same application in NetBeans (also in Intellij IDEA) .

  • Possible duplicate of [Getting NoSuchMethodError: javax.persistence.Table.indexes() while performing JPA query](http://stackoverflow.com/questions/22431153/getting-nosuchmethoderror-javax-persistence-table-indexes-while-performing-jp) – Joachim Rohde Mar 15 '17 at 16:27

1 Answers1

0

There are many answers in stackoverflow to solve this problem.

JB Nizet has already dig this issue and told the root cause and solution procedure as below:

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

For more you can check the related answer:

  1. NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index
  2. java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Why it compile well thus? I got exception only during debug attempt. And application run well without debug outside IDE. Probably this is some kind of gradle problem. – Ekaterina Ivanova iceja.net Mar 20 '17 at 15:44
  • @Catherine debug time exception is actually occurs for another reason. It may be possible that multiple threads are waiting for a reply. When a reply packet is received a notifyAll() is performed in the receive manager which will let one thread check the reply packet queue. If the reply is not for the thread that was waiting, it goes into a wait again, but does not notify to allow another waiting thread to check the reply queue. For this reason, this problem occurs. – SkyWalker Mar 20 '17 at 15:55
  • Connected to the target VM, address: '127.0.0.1:59507', transport: 'socket' Mar 20, 2017 6:59:23 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.9.Final} Mar 20, 2017 6:59:23 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found Disconnected from the target VM, address: '127.0.0.1:59507', transport: 'socket' Mar 20, 2017 6:59:24 PM entities.CarScrapperHibernateUtil SEVERE: null java.lang.NoSuchMethodError: – Ekaterina Ivanova iceja.net Mar 20 '17 at 16:11
  • It fail during running in debug, but it run well without debugging. It failed on Hibernate initialisation stage " sessionFactory = new Configuration().configure().buildSessionFactory();" it is different exception now : java.lang.NoSuchMethodError: org.hibernate.annotations.common.reflection.java.JavaReflectionManager.setMetadataProvider(Lorg/hibernate/annotations/common/reflection/MetadataProvider;)V I do not now how it happened, I have changed gradle dependencies – Ekaterina Ivanova iceja.net Mar 20 '17 at 16:23
  • @Catherine which hibernate version are you using ? – SkyWalker Mar 20 '17 at 16:26
  • Hibernate Core {5.2.9.Final} – Ekaterina Ivanova iceja.net Mar 20 '17 at 16:27
  • is there any hibernate-commons-annotations in your gradle ? – SkyWalker Mar 20 '17 at 16:30
  • compile "org.hibernate:hibernate-commons-annotations:+" you can see dependencies in the initial post – Ekaterina Ivanova iceja.net Mar 20 '17 at 16:38
  • remove the specified portion. and clean and build. Hope it will solve your issue. From Hibernate v3.6 the annotations classes have been merged into core. Just remove the dependency on hibernate-commons-annotations and this should be resolved. – SkyWalker Mar 20 '17 at 16:44
  • This resolve the problem but "exception: Table.indexes() " rised again I am reading your links – Ekaterina Ivanova iceja.net Mar 20 '17 at 17:25
  • @Catherine in every IDE, this type of timeout exception arises in debug time because of waiting multiple thread for reply. As I stated before. That is the issue. – SkyWalker Mar 20 '17 at 17:29
  • I have added "compile "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:+" but situation is the same. What is most important exception rises only during debug – Ekaterina Ivanova iceja.net Mar 20 '17 at 17:57
  • timeout exception and nosuchmethoderror exception is mostly happens in debug time. @Catherine – SkyWalker Mar 20 '17 at 18:07