【发布时间】:2021-09-27 14:39:18
【问题描述】:
只有在创建特定实体表之后,才能在 Spring Boot 中让休眠添加一些 data.sql。 (我不想在初始化 Spring Boot 应用程序时初始化架构和数据)
package io.fall.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "userprofile")
public class UserProfile {
@Id
@GeneratedValue
private int id;
private int theme;
private String userName;
UserProfile(){}
public int getTheme() {
return theme;
}
public void setTheme(int theme) {
this.theme = theme;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
我想在hibernate创建实体表userprofile之后插入这些值
INSERT INTO userprofile (id,theme,userName,summary)
VALUES (1, 1 , 'John Doee'),
(2, 2 , 'Jenny Doee'),
(3, 3 , 'James Doee');
【问题讨论】:
-
Hibernate 没有这样的功能。但是你可以使用 spring 来实现,甚至你可以使用 flyway 或 liquibase 来做这些事情。
标签: java sql spring-boot hibernate spring-data-jpa