Search code examples
mysqlspring-bootdockerhibernate

Hibernate is not generating any table


I'm learning Spring microservices and faced an issue: So first I've this docker compose file:

version: '3.1'
services:
  mongo:
    image: mongo
    container_name: mongo
    restart: always
    ports:
      - 27017:27017

  mysql:
    image: mysql
    restart: always
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: 'rootpassword'
    ports:
      - "3307:3306"

  elasticsearch:
    image: elasticsearch:8.11.3
    container_name: elasticsearch
    ports:
      - 9200:9200
      - 9300:9300
    environment:
      discovery.type: single-node

And here is the yaml file for the configuration:

server:
  port: 7203

spring:
  application:
    name: taskservice

  datasource:
    url: jdbc:mysql://localhost:3307/TaskDB
    username: root
    password: rootpassword
    driver-class-name: com.mysql.cj.jdbc.Driver
    jpa:
      show-sql: true
      hibernate:
        ddl-auto: update
      properties:
        hibernate:
          dialect: org.hibernate.dialect.MySQLDialect

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:7201/eureka/

I've tested the connection and added the schema called "TaskDB" on DataGrip. When I run the application the table is not generated. Here is the entity class:

@Entity
@Table(name = "tasks")
@EqualsAndHashCode(of = {"id"})
public class Task extends CoreEntity {
    @Id
    @Getter
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "id")
    private String id;
    @Getter
    @Setter
    @Column(name = "title")
    private String taskTitle;
    @Getter
    @Setter
    @Column(name = "description", length = 600)
    private String taskDescription;
    @Getter
    @Setter
    @Column(name = "notes")
    private String notes;
    @Getter
    @Setter
    @Column(name = "assignne", length = 50)
    private String assignee;
    @Getter
    @Setter
    @Column(name = "startDate")
    private Timestamp taskStartDate;
    @Getter
    @Setter
    @Enumerated(EnumType.ORDINAL)
    private TaskStatus taskStatus;
    @Getter
    @Setter
    @Enumerated(EnumType.ORDINAL)
    private PriorityType priorityType;
}

Why is this table not getting generated?


Solution

  • Setting jpa should be under spring, not under the datasource. The full correct key is spring.jpa.hibernate.ddl-auto=update