模式验证:缺少表 \[游戏\]

新手上路,请多包涵

我认为这可能是重复的: 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;
    }
}

原文由 Rares 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 524
1 个回答

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

这个答案更详细地说明了 validate 的作用。

休眠 - hibernate.hbm2ddl.auto = 验证

具体来说,

检查表、列、id 生成器是否存在

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

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

原文由 Darren Forsythe 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进