我认为这可能是重复的:模式验证:缺少表[hibernate_sequences],但我无法弄清楚。
因此,在我的application.properties文件中,我有此选项:spring.jpa.hibernate.ddl-auto=validate并且收到此错误:
Schema-validation: missing table [game]
为什么我收到这个?
这是我的Game课和User课:
游戏:
@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
Run Code Online (Sandbox Code Playgroud)
用户:
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
当我更改为 Hibernate 5.4.0.Final 时,我得到了相同的结果。Hibernate 突然无法识别默认架构,或者驱动程序没有正确返回架构。我能够通过将模式定义添加到表定义来绕过它。
@Table(name = "GAME", schema = "PUBLIC")
Run Code Online (Sandbox Code Playgroud)
或者通过在persistence.xml 中添加默认架构。
<property name="hibernate.default_schema" value="PUBLIC" />
Run Code Online (Sandbox Code Playgroud)
validate在某种程度上证明实体与目标兼容,这并非万无一失。无论如何,无论您要针对game哪个数据库进行验证,都没有一个用于存储实体的表。
该答案将更详细地说明validate功能。
特别,
检查表,列,id生成器的存在
不知道您的数据库/期望(您是希望创建它,还是使用Flyway / Liquibase创建/更新数据库等),如果validate您的用例是正确的,我将无法回答。
您可以尝试create-drop在启动/关闭时创建和删除表,但这不是对数据库进行任何生产控制的解决方案。
将 Spring Boot 与 FlywayDB 结合使用时可能会出现此错误。该问题可能是由于 FlywayDB 使用的脚本文件的命名约定错误造成的。
https://flywaydb.org/documentation/migrations#naming
| 归档时间: |
|
| 查看次数: |
24150 次 |
| 最近记录: |