Search code examples
javamavenspring-boothibernate-4.xhibernate-5.x

Maven, Can't go from Hibernate 4 to Hibernate 5 in my pom


With my Spring Boot 1.2.5 project, I can't figure out how to go from Hibernate 4 to Hibernate 5. Currently, I have this in my pom:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.3.Final</version>
</dependency>           

And that works great. If I replace it with this:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
</dependency>   
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.2.Final</version>
</dependency>

Not so much. It throws a pile of exceptions like this:

Caused by: java.lang.ClassNotFoundException:     org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$Work
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at     org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49)

I tried adding the JBoss repository to my pom, but that made no difference:

<repositories>

    <repository>  
      <id>jboss-public-repository-group</id>  
      <name>JBoss Public Maven Repository Group</name>  
      <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>  
      <layout>default</layout>  
      <releases>  
        <enabled>true</enabled>  
        <updatePolicy>never</updatePolicy>  
      </releases>  
      <snapshots>  
        <enabled>false</enabled>  
        <updatePolicy>never</updatePolicy>  
      </snapshots>  
    </repository>      

</repositories>

What's the trick?

UPDATE:

Dependency tree as requested:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building UA_Decision 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.9:tree (default-cli) @ decision ---
[INFO] edu.mit.ua:decision:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:4.2.2.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.2.5.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.2.5.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] |  |  |  +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] |  |  |  \- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  |  |     \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:2.1.4.RELEASE:compile
[INFO] |  |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.9:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.2.5.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.23:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.23:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.23:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.23:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.6:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.6:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.6:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.1.7.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.2.5.RELEASE:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  \- org.springframework:spring-test:jar:4.1.7.RELEASE:test
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.10.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.0.2.Final:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.2.2.Final:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:5.0.2.Final:compile
[INFO] |  \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] |     \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- com.oracle:ojdbc7:jar:12.1.0.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.5.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjrt:jar:1.8.6:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.5.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-jdbc:jar:4.1.7.RELEASE:compile
[INFO] |  |  \- org.apache.tomcat:tomcat-jdbc:jar:8.0.23:compile
[INFO] |  |     \- org.apache.tomcat:tomcat-juli:jar:8.0.23:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.7.3.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.9.3.RELEASE:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.7.RELEASE:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.7:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.7:compile
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:1.2.5.RELEASE:compile
[INFO] |  \- org.json:json:jar:20140107:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:1.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-messaging:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework.amqp:spring-rabbit:jar:1.4.5.RELEASE:compile
[INFO] |     +- com.rabbitmq:amqp-client:jar:3.5.5:compile
[INFO] |     +- org.springframework.retry:spring-retry:jar:1.1.2.RELEASE:compile
[INFO] |     \- org.springframework.amqp:spring-amqp:jar:1.4.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.5.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.2.5.RELEASE:compile
[INFO] +- org.springframework.ws:spring-ws-core:jar:2.2.1.RELEASE:compile
[INFO] |  +- org.springframework.ws:spring-xml:jar:2.2.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-oxm:jar:4.1.7.RELEASE:compile
[INFO] +- com.oracle:ucp:jar:12.1.0.2:compile
[INFO] \- com.oracle:ons:jar:12.1.0.2:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.571 s
[INFO] Finished at: 2015-10-28T18:10:50-04:00
[INFO] Final Memory: 20M/437M
[INFO] ------------------------------------------------------------------------

Solution

  • If you want to override versions which are managed by Spring Boot, you should only use the properties which are provided by Spring Boot. You can check the available properties in the pom.xml for the project spring-boot-dependencies (https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml).

    In your case, you should define the following properties:

    <hibernate.version>5.0.3.Final</hibernate.version>
    <spring.version>4.2.2.RELEASE</spring.version>
    

    This will ensure that all required libraries for that framework are pulled in with the same version.