Spring Boot - repository field required a bean named 'entityManagerFactory' that could not be found

spring-boot-starter-data-jpa will pull in all the hibernate dependencies you need. Using spring boot release 1.5.1, it will pull in hibernate-core:5.0.11 and hibernate-entitymanager:5.0.11. In addition to being unnecessary, your hibernate dependency versions are mismatched which is what I'm guessing is causing the error.

Try removing these dependencies from your pom.xml.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.4.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.3.Final</version>
</dependency>
Jules S.

Try those dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>   
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

instead of:

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

Hibernate-core 5.2.0 have problem with Spring Data JPA while process collection. Hibernate-core 5.2.1 and above is ok with Spring Data JPA when you use Spring Data JPA.

From hibernate onwards 5.2.0. hibernate-entitymanager is no longer needed.

So try to change:

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

To this version:

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

This fixed it for me.

Try deleting your dependencies from

  • ~/.m2/repository (Linux)
  • C:/Users/your_user/.m2/repository (Windows)

and further updating your project dependencies either through your IDE's update dependencies functionality, or by running mvn install from your project's folder.

The problem might be due to version mismatch. Problem can be solve by specifying the dependency like this (since version is not mentioned, its auto managed)

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>