Spring project does not auto-create the database(MYSQL)

spring.jpa.hibernate.ddl-auto=update not working
spring boot create database if not exists mysql
spring.jpa.generate-ddl=true meaning
table not created in mysql database spring-boot
spring boot create database if not exists postgres
spring boot mysql
spring boot bootstrap database
how to set schema name in datasource spring boot

For a project I have to create a database using spring-boot, hibernate and mysql. I don't have an error per say, just the database does not get created without an error. I am not sure, however why and how I can fix it.

Logs I get when I run the app:

2019-10-13 20:24:02.652  INFO 20288 --- [           main] D.p.t.D.p.try1.DsProiectTry1Application  : Starting DsProiectTry1Application on DESKTOP-3KOFPIQ with PID 20288 (started by Diana in D:\AN 4\PROIECTE DS INCERCARI\DS-proiect-try1)
2019-10-13 20:24:02.652  INFO 20288 --- [           main] D.p.t.D.p.try1.DsProiectTry1Application  : No active profile set, falling back to default profiles: default
2019-10-13 20:24:03.539  INFO 20288 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-10-13 20:24:03.557  INFO 20288 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 repository interfaces.
2019-10-13 20:24:04.094  INFO 20288 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2d7cd334] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-10-13 20:24:04.141  INFO 20288 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$acfd2066] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-10-13 20:24:04.676  INFO 20288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-10-13 20:24:04.707  INFO 20288 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-13 20:24:04.707  INFO 20288 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.26]
2019-10-13 20:24:04.816  INFO 20288 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-10-13 20:24:04.832  INFO 20288 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2117 ms
2019-10-13 20:24:05.050  INFO 20288 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-10-13 20:24:05.253  INFO 20288 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-10-13 20:24:05.316  INFO 20288 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-10-13 20:24:05.378  INFO 20288 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.12.Final}
2019-10-13 20:24:05.378  INFO 20288 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-10-13 20:24:05.509  INFO 20288 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-10-13 20:24:05.616  INFO 20288 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2019-10-13 20:24:05.788  INFO 20288 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@ff21443'
2019-10-13 20:24:05.788  INFO 20288 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-10-13 20:24:06.366  INFO 20288 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-13 20:24:06.413  WARN 20288 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-10-13 20:24:06.559  WARN 20288 --- [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2019-10-13 20:24:06.900  INFO 20288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-10-13 20:24:06.900  INFO 20288 --- [           main] D.p.t.D.p.try1.DsProiectTry1Application  : Started DsProiectTry1Application in 4.611 seconds (JVM running for 5.055)

I have tried several changes on the application properties files and hibernate.cfg.xml( yet it still is not recognised) but none were helping/ made some changes .

My application properties files is :

# Connection url for the database "netgloo_blog"
spring.datasource.url = jdbc:mysql://localhost:3306/mydbds?useSSL=false&autoReconnect=true

# Username and password
spring.datasource.username = root
spring.datasource.password =

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# ===============================
# = JPA / HIBERNATE
# ===============================

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = create-drop
spring.datasource.driverClassName=com.mysql.jdbc.Driver
server.port=8080

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>DS.proiect.try1</groupId>
    <artifactId>DS-proiect-try1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>DS-proiect-try1</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

my hibernate.cfg.xml file:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- SQL Dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.org.hibernate.dialect.MySQLDialect</property>

        <!-- Database Connection Settings -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydbds</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>

        <!-- Mapping With Model Class Containing Annotations -->
        <mapping class=" DS.proiect.try1.DS.proiect.try1.Entities.Doctor" />
    </session-factory>
</hibernate-configuration>

My intelij project strcuture is :https://imgur.com/zoSOKhL

Some of my tables from the entity package :

@Entity
@Table(name="Caregiver")
public class Caregiver {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idCaregiver", unique=true, nullable = false)
    private int idCaregiver;

    @Column(name="caregiverName")
    private String caregiverName;

    @Column(name="caregiverSurname")
    private String caregiverSurname;

    @Column(name="caregiverGender")
    private String caregiverGender;

    @Column(name="caregiverAddress")
    private String caregiverAddress;

    @Column(name="caregiverBirthdate")
    private String caregiverBirthdate;

    @Column(name="caregiverEmail")
    private String caregiverEmail;

    @Column(name="caregiverPassword")
    private String caregiverPassword;

    @OneToMany(mappedBy = "Caregiver_idCaregiver", cascade = CascadeType.ALL,fetch= FetchType.LAZY)
    private Set<Patient> patientList;


@Entity
@Table(name = "Patient")
public class Patient {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idPatient", unique=true, nullable = false)
    private int idPatient;

    @Column(name="patientName")
    private String patientName;

    @Column(name="patientSurname")
    private String patientSurname;

    @Column(name="patientGender")
    private String patientGender;

    @Column(name="patientBirthdate")
    private Date patientBirthdate;

    @Column(name="patientAddress")
    private String patientAddress;

    @Column(name="patientEmail")
    private String patientEmail;

    @Column(name="patientPassword")
    private String patientPassword;

    @ManyToOne
    @JoinColumn(name="Caregiver_idCaregiver")
    Caregiver Caregiver_idCaregiver;

and the relationship between them should be something like this:https://imgur.com/undefined

I should have the whole database created by spring-boot but it does not work like that and I have no idea why. Any help is appreciated, thank you!

In application.properties change to spring.datasource.url = jdbc:mysql://localhost:3306/yourDB?useSSL=false and spring.jpa.hibernate.ddl-auto = create.

Use this dialect spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect and this dependency

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

With SpringBoot you do not need anymore to use the hibernate.cfg.xml. SpringBoot will do this job for us avoiding boilerplate code. Just use application properties to set your app...

To create your DB with SpringBoot bear in mind that you need just three setting step:

1 - MySql Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://localhost:3306/YOURBD?useSSL=false
spring.datasource.username = root
spring.datasource.password = root
2 - Hibernate Properties

The SQL dialect makes Hibernate generate better SQL for the chosen database

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

And the last one

3 - Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update or create

and do not forget the dependency..

Spring project does not auto-create the database(MYSQL), Currently there are no answers on this question on the stackoverflow. together to host and review code, manage projects, and build software together. for MySQL DB while using "spring.jpa.hibernate.ddl-auto=create"? We'll be building a simple note-taking application that uses Spring Data JPA to store and retrieve data in a relational database — MySQL. Dependencies. You only need spring-data-starter-data-jpa and mysql-connector-java dependencies to use MySQL database with Spring Data JPA.

You need to pass all hibernate property valus in application.properties file

Why Spring Boot doesn't create schema for MySQL DB while using , How to get your DB Tables automatically created with Spring Boot configuration that will let Hibernate create the Database tables out of your Entity beans: spring.datasource.url=jdbc:mysql://localhost:3306/mysqltutorial? validate: validate the schema, makes no changes to the database. update: update  In this Spring turorial, you will learn how to code a Spring Boot application that uses Spring Data JPA to access data from a relational database - MySQL.. You know, Spring Data JPA greatly simplifies the way programmers write code for the data access layer, e.g. writing only repository interfaces that extend CrudRepository / JpaRepository.

Spring boot does not create the database. Spring boot connect the database and create and update tables as per your java entity class.

Create Database with Spring Boot, MySQL, & JPA ddl-auto=create , Spring Boot makes it really easy to manage our database changes in an easy way. we're working with JPA – and define a simple Country entity in our project: If we run our application, Spring Boot will create an empty table for us, It's also important to remember to turn off automatic schema creation to  Obviously there is a need for some storage which could be a simple H2 if Spring Boot is already on the table but as this is a tutorial about a let’s say “full stack” service, we are going to use an external database, namely MySQL. On start.spring.io, create a new project using Web, JPA, MySQL.

How to get your DB Tables automatically created with Spring Boot, Be careful when switching from in-memory to a 'real' database that you do not make Spring Boot can automatically create the schema (DDL scripts) of your name of the database ( hsqldb , h2 , oracle , mysql , postgresql , and so on). mysql> use testdb; mysql> source cities_mysql.sql With the source command, we execute the SQL statements. Spring Boot MySQL example. The following application is a simple Spring Boot web application, which uses MySQL database. We have a home page with a link to display data from a database table.

Guide on Loading Initial Data with Spring Boot, You will create a MySQL database, build a Spring application, and connect it to the newly created The following image shows the Initializr set up for this sample project: spring.jpa.hibernate.ddl-auto=update spring.datasource.url=​jdbc:mysql://${ create : Creates the database every time but does not drop it on close. none: The default for MySQL. No change is made to the database structure. update: Hibernate changes the database according to the given entity structures. create: Creates the database every time but does not drop it on close. create-drop: Creates the database and drops it when SessionFactory closes.

85. Database Initialization, The first thing we'll create is a managed MySQL server. Note means that Spring Boot will automatically create a database schema at Otherwise, our Java server would not use the same date format as the database, which  In the spring boot reference,it said:. When a class doesn’t include a package declaration it is considered to be in the “default package”. The use of the “default package” is generally discouraged, and should be avoided.

Comments
  • Try adding the following property along with the @Jailson Evora's answer jdbc:mysql://localhost:3306/mydbds?useSSL=false&autoReconnect=true&createDatabaseIfNotExist=true .This will create the database if it is not present.
  • I have that dependency. I have done the changes and nothing happens. No errors but no DB either.
  • create-drop will drop Database when we stop debugging...