3


I am doing a prototype using Spring Boot on an existing project with many Hibernate dependencies. I am trying to define a custom LocalEntityManagerFactoryBean and it is here that I get this error:

java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

I have tried updating my hibernate versions (could not use all latest versions due to project backward compatibility causing many other compile errors) but with the following hibernate dependency graph could get it to compile but still get this runtime dependency error. When I searched for this error all results to pointed to upgrade of Hibernate 4 and JPA 2.1. We were already using Hibernate 4+, so just changed the version a little higher but no luck. The following dependency graph from Gradle shows that I do not have any old version of "org.hibernate.javax.persistence:hibernate-jpa-2.0-api"

|    +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
|    |    +--- org.hibernate:hibernate-core:4.3.7.Final
|    |    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
|    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.hibernate:hibernate-validator:5.1.3.Final
|    |    |         +--- org.hibernate:ejb3-persistence:1.0.2.GA
|    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final
|    |    |    |    |    |    +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
|    |    |    |    |    |    +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
|    |    +--- org.hibernate:hibernate-core:4.3.7.Final
|    |    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
|    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.hibernate:hibernate-validator:5.1.3.Final
|    |    |         +--- org.hibernate:ejb3-persistence:1.0.2.GA
|    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final
|    |    |    |    |    |    +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
|    |    |    |    |    |    +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
|    |    +--- org.hibernate:hibernate-core:4.3.7.Final
|    |    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
|    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.hibernate:hibernate-validator:5.1.3.Final
|    |    |         +--- org.hibernate:ejb3-persistence:1.0.2.GA
|    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final
|    |    |    |    |    |    +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
|    |    |    |    |    |    +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
|    |    +--- org.hibernate:hibernate-core:4.3.7.Final
|    |    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
|    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.hibernate:hibernate-validator:5.1.3.Final
|    |    |         +--- org.hibernate:ejb3-persistence:1.0.2.GA
|    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final
|    |    |    |    |    |    +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
|    |    |    |    |    |    +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
|    |    +--- org.hibernate:hibernate-core:4.3.7.Final
|    |    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
|    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    +--- org.hibernate:hibernate-validator:5.1.3.Final
|    |    |         +--- org.hibernate:ejb3-persistence:1.0.2.GA
|    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final
|    |    |    |    |    |    +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
|    |    |    |    |    |    +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
|    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    |    |    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    |    |    |    |    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    |    |    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
|    |    +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
|    |    +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
|    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
|    |    |    |    +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta

Any pointers will be of much help.

Thanks,
Paddy

Paddy
  • 3,472
  • 5
  • 29
  • 48
  • 1
    You have version conflicts between different hibernate versions. Please make sure that you anly have hibernate 4.3.x in your war file. – Jens Dec 09 '14 at 07:49
  • Hi @Jens, yes I will try to remove all other versions but there are some dependencies like hibernate-common-annotations or something like that that is still at 3.5.6 and worse still has not been upgraded to use hibernate-jpa-api-2.1 for some reason. And are you referring I should have only 4.3.x of core, entitymanager etc.? Just trying to understand is the problem on Hibernate side or JPA side (I thought Hibernate my existing Hibernate 4.1.2 core library dependency was referring a class only available in JPA 2.1, so if I upgrade the api dependency version, it should have worked isn't it)? – Paddy Dec 09 '14 at 08:27
  • Also @Jens, do you know if there is a way to exclude a specific version of a dependency alone? – Paddy Dec 09 '14 at 08:31
  • For the annotations try to use `org.hibernate.common:hibernate-commons-annotations:4.0.5.Final` – Jens Dec 09 '14 at 08:34
  • Oops sorry misspelt it, there is apparently a hibernate-annotations that is still at 3.5.6. Any idea on global exclude by version? – Paddy Dec 09 '14 at 08:35
  • Read [this](http://www.gradle.org/docs/current/userguide/dependency_management.html) for understanding exclude mechanism – Jens Dec 09 '14 at 08:36
  • I guess you are referring options like 'force' or exclude at a dependency inclusion level like compile('depA') { exclude('depB') } kind of declaration? The problem is that my project structure is quite complex now - that's why I wanted to find a workaround to globally exclude these versions, otherwise I may to have end up fixing a lot of places in the project before I can continue. – Paddy Dec 09 '14 at 08:53

1 Answers1

1

Try excluding dependencies that you don't need and enforcing versions for those you want. E.g.:

configurations.all { conf ->
        exclude group: 'org.hibernate', module: 'hibernate-annotations'
        resolutionStrategy {

            // Forces one verion among the project
            force "org.hibernate.common:hibernate-commons-annotations:4.0.5.Final"
        }
}
Kranach
  • 740
  • 2
  • 9
  • 24
  • Thanks @Kranach, I did not have to force include anything, just removing 'hibernate-annotations' helped me get over. Apparently newer versions of hibernate-core seem to include whatever was there in hibernate-annotations library. – Paddy Dec 10 '14 at 09:31