0

I´m using spring boot with jpa to automatically create the tables, but for some reason when i start the application , the tables are not being created.

This is my application.properties:

    #Mysql Config
spring.datasource.url=jdbc:mysql://localhost:3306/election?useTimezone=true&serverTimezone=UTC&createDatabaseIfNotExist=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=create

This is a model example from my app. enter image description here

And 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.3.0.M3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.dataprev.election</groupId>
    <artifactId>election</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>election</name>
    <description>Demo System Election</description>

    <properties>
        <java.version>13</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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>

i already conect to the database in intellij too. I saw other similar questions but didn´t resolve form me.

Rômulo Sorato
  • 1,570
  • 5
  • 18
  • 29

2 Answers2

0

Might be a issue with dialect.Change your hibernate dialect property to and try again,

 spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL57Dialect
Chamith Madusanka
  • 471
  • 2
  • 4
  • 11
0

You can achieve this by enabling SSL in MySQL connection.

spring.datasource.url=jdbc:mysql://localhost/my_db?useSSL=true&createDatabaseIfNotExist=true
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.datasource.username=james
spring.datasource.password=bond
spring.jpa.hibernate.ddl-auto=create
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

But be careful with DDL commands, try managing database schema separately. It will give you better control over your application.

Vibhay Sachan
  • 161
  • 12