【问题标题】:Spring Boot App keeps creating a new database TablesSpring Boot App 不断创建新的数据库表
【发布时间】:2018-11-12 17:28:10
【问题描述】:

所以我有一个由 Hibernate 注释支持的实体,但问题是每当我完全重新启动我的应用程序时,表中的数据都会丢失。

实体文件为:

package hello;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Customer {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;

    protected Customer() {}

    public Customer(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Override
    public String toString() {
        return String.format(
                "Customer[id=%d, firstName='%s', lastName='%s']",
                id, firstName, lastName);
    }

}

【问题讨论】:

  • 你的数据库是什么?

标签: java database spring-mvc spring-boot jdbc


【解决方案1】:

在您的 Applications.properties 文件中添加:

spring.jpa.hibernate.ddl-auto=update

这将使用您现有的表,而不是每次重新启动 Spring Boot 应用程序时都销毁和创建新表。

【讨论】:

    猜你喜欢
    • 2020-10-22
    • 2018-12-30
    • 2015-04-26
    • 2018-08-22
    • 2021-01-09
    • 2021-10-30
    • 2018-12-24
    • 2014-12-27
    • 2020-02-08
    相关资源
    最近更新 更多