0

When I run the project, does not create tables in MySQL.

I tried to change the spring.jpa.hibernate.ddl-auto = update to create-drop and also does not to create.

No error appears in the log.

My class

@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity(name = "tb_user")
public class User {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

 @Column(length = 75, nullable = false)
 private String name;

 @Column(length = 75, nullable = false, unique = true)
 private String email;

 @Column(length = 100, nullable = false)
 private String password;
 }

My pom.xml

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </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>

my application.properties

spring.datasource.url=jdbc:mysql://localhost:3307/db_spring?useTimezone=true&serverTimezone=UTC
spring.datasource.username=sa
spring.datasource.password=1234567
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
halfer
  • 19,824
  • 17
  • 99
  • 186
Felipe
  • 1
  • Have you tried solutions in this thread? https://stackoverflow.com/questions/26881739/unable-to-get-spring-boot-to-automatically-create-database-schema – Dai Jun 30 '20 at 03:24
  • Do you see any errors in the logs? – Simon Martinelli Jun 30 '20 at 05:40
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jun 30 '20 at 09:05
  • I think you're probably missing the hibernate dialect? – bbortt Jun 30 '20 at 10:47
  • first, you should create your database yourselff. – Morteza Malekabadi Jun 30 '20 at 11:17
  • my dialect is configured and my database created, but no error message appears in my log – Felipe Jun 30 '20 at 14:27

1 Answers1

0

Try adding

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

also check you are using @EnableAutoConfiguration and entity classes are in same package or subpackage

Tanmay Naik
  • 586
  • 1
  • 4
  • 16
  • I tried to add `spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect`, but it still doesn't work and the annotations are right – Felipe Jun 30 '20 at 14:14