gpt4 book ai didi

jpa - 架构验证 : missing table [game]

转载 作者:行者123 更新时间:2023-12-03 13:43:10 25 4
gpt4 key购买 nike

我认为这可能是重复的:Schema-validation: missing table [hibernate_sequences]但我想不通。

所以在我的 application.properties文件我有这个选项:spring.jpa.hibernate.ddl-auto=validate我收到此错误:
Schema-validation: missing table [game]
为什么我会收到这个?

这是我的 Game类(class)和 User类(class):

游戏:

@Entity
public class Game {
@Id
@Column(name = "GAME_NUMBER")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long gameNumber;

private int playerScore;
private int NPCScore;
private Date datetime;

@ManyToOne
@JoinColumn(name="USER_ID")
private User user;

public Game() {}

public Game(int playerScore, int nPCScore, Date datetime) {
super();
this.playerScore = playerScore;
this.NPCScore = nPCScore;
this.datetime = datetime;
}

public User getUser() {
return user;
}
} + getters & setters

用户:
@Entity
public class User {
@Id
@Column(name = "USER_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long userId;

private String username;
private String password;

@OneToMany(mappedBy="user",cascade=CascadeType.ALL)
private List<Game> games;

@ElementCollection
private List<Date> startSessions;

public User() {}

public User(String username, String password, List<Game> games, List<Date> startSessions) {
super();
this.username = username;
this.password = password;
this.games = games;
this.startSessions = startSessions;
}
}

最佳答案

validate验证实体与目标兼容,在一定程度上它不是万无一失的。无论如何,无论您尝试验证的数据库都没有名为 game 的表。在其中存储实体。

这个答案更详细地介绍了 validate做。

Hibernate - hibernate.hbm2ddl.auto = validate

具体来说,

checks the presence of tables, columns, id generators



不知道您的数据库/期望(您是否希望创建它,或使用 Flyway/Liquibase 创建/更新数据库等)我无法回答是否 validate适合您的用例。

你可以试试 create-drop在启动/关闭时创建和删除表,但这不是对数据库进行任何生产控制的解决方案。

关于jpa - 架构验证 : missing table [game],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44479406/

25 4 0