星辰
发布于

Hibernate 未生成任何表

我正在学习 Spring 微服务并遇到一个问题: 所以首先我有这个 docker compose 文件:

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

以下是配置的 yaml 文件:

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/

我已经测试了连接,并在 DataGrip 上添加了名为“TaskDB”的架构。当我运行应用程序时,不会生成表。 以下是 entity 类:

@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;
}

为什么没有生成此表?

浏览 (25)
点赞
收藏
1条评论
星辰
星辰
jpaspringdatasourcespring.jpa.hibernate.ddl-auto=update 正确密钥
点赞
评论