Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Spring with Hibernate Integrating Hibernate with Spring Add JPA Annotations to Entities

org.springframework.beans.factory.BeanCreationException

I keep getting this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/teamtreehouse/giflib/config/DataConfig.class]: Invocation of init method failed; nested exception is org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in URL file: /giftlib-hibernate/build/resources/main/hibernate.cfg.xml. Message: null

I have came across other examples of this error but none that had a "Message: null" error.

I also have had a lot of issues following courses with the same exact gradle build file. Often I need more or different dependencies than in the videos. This might be the issue. I am using gradle 5.0

this is my build.gradle file. I already tried using the one from the github repo for the course but that did not work.

plugins {
    id 'java'
    id 'idea'
    id 'eclipse'
    id 'org.springframework.boot' version '1.4.3.RELEASE'
}

group 'com.teamtreehouse'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.thymeleaf.extras:thymeleaf-extras-java8time:2.1.0.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
    compile 'javax.xml.bind:jaxb-api:2.3.0'
    compile 'org.hashids:hashids:1.0.1'

    // https://mvnrepository.com/artifact/org.springframework/spring-orm
    compile group: 'org.springframework', name: 'spring-orm', version: '5.0.7.RELEASE'
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-core
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.2.Final'
    // https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2
    compile 'org.apache.tomcat:tomcat-dbcp:9.0.10'
    compile 'com.h2database:h2:1.4.197'
}
Linus Johansson
Linus Johansson
12,469 Points

i got the same error, did you ever find out what the problem was?

I was able to get it working with this build.gradle file

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-securing-web'
    version =  '0.1.0'
    launchScript()
}

repositories {
    mavenCentral()
    jcenter()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    // Spring
    compile 'org.springframework.boot:spring-boot-starter:2.0.4.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa:2.0.4.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-security:2.0.4.RELEASE'
    compile 'org.springframework:spring-orm:5.0.8.RELEASE'
    // Thymeleaf
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf:2.0.4.RELEASE'
    compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE'


    // Database
    compile 'org.hibernate:hibernate-core:5.3.4.Final'
    compile 'com.h2database:h2:1.4.197'
    compile 'javax.xml.bind:jaxb-api:2.3.0'
    compile 'com.sun.xml.bind:jaxb-impl:2.3.0'
    compile 'javax.activation:activation:1.1.1'
    compile 'javax.validation:validation-api:2.0.1.Final'
    compile 'com.sun.xml.bind:jaxb-core:2.2.11'
    compile 'org.apache.tomcat:tomcat-dbcp:8.0.32'

    testCompile 'org.springframework.boot:spring-boot-starter-test:2.0.4.RELEASE'
    testCompile 'org.springframework.security:spring-security-test:5.0.7.RELEASE'
    testCompile 'junit:junit:4.12'
}

1 Answer

Linus Johansson
Linus Johansson
12,469 Points

ohh nice i'll try it out, thanks man