我认为可能有可能这样做:Schema-validation: missing table [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
用户:
@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;
}
}
答案 0 :(得分:3)
validate
验证实体是否与目标兼容,在某种程度上它并非万无一失。无论如何,您尝试验证的任何数据库都没有一个名为game
的表来存储实体。
这个答案详细介绍了validate
的作用。
Hibernate - hibernate.hbm2ddl.auto = validate
具体而言,
检查表,列,id生成器的存在
不知道您的数据库/期望(您是否希望创建它,或使用Flyway / Liquibase创建/更新数据库等)。如果validate
对您的用例是正确的,我无法回答。
您可以尝试create-drop
在启动/关闭时创建和删除表,但这不是对数据库的任何生产控制的解决方案。
答案 1 :(得分:2)
我与更改为Hibernate 5.4.0.Final相同。 Hibernate突然无法识别默认架构,或者驱动程序未正确返回架构。 我可以通过将架构定义添加到表定义中来绕过它。
<property name="hibernate.default_schema" value="PUBLIC" />
或通过在persistence.xml中添加默认架构。
'|'
答案 2 :(得分:1)
别忘了权限: 授予选择,插入,更新,删除,更改ON table_name到usr_name;
答案 3 :(得分:0)
在将spring boot与flywayDB一起使用时,可能会出现此错误。 问题可能是由于flywayDB使用的脚本文件命名约定错误。