MySQL 表在重新启动 Linux 应用程序后为空

MySQL tables are empty after restarting Linux application

我正在使用 hibernate 将实体对象保存在本地 运行 数据库中。

一切正常(连接到数据库,add/delete/update 个条目),只要应用程序是 运行。

我正在使用此代码将条目传递给 table:

CrudRepository:

public interface ArticleRepository extends CrudRepository<ArticleEntity, Integer> {
}

DB accessor method:

public void addArticleEntity(ArticleEntity articleEntity){
    articleRepository.save(articleEntity);
}

重新启动应用程序后,所有条目都消失了,只有空 table 本身永久保留。

如何永久保存这些 table 条目?

persist 方法旨在将新的实体实例添加到持久性上下文,即将实例从瞬态转换为持久状态。

我们通常在要向数据库中添加一条记录(持久化一个实体实例)时调用它:

Person person = new Person();
person.setName("John");
session.persist(person);

更多信息: https://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate

很抱歉张贴了如此随意的信息,我根本不知道从哪里开始搜索。即使如此,否决票也无济于事。

解决方案是将 spring.jpa.hibernate.ddl-auto=create(显然在重新启动时创建新表)设置为 spring.jpa.hibernate.ddl-auto=update

它可能会对寻找类似术语的人有所帮助。