所以我有一个由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);
}
}
答案 0 :(得分:0)
在Applications.properties文件中添加:
spring.jpa.hibernate.ddl-auto=update
这将使用您现有的表,而不是每次您重新启动Spring Boot应用程序时都破坏并创建新表。