模式验证:缺少表 [游戏] [英] Schema-validation: missing table [game]

查看:23
本文介绍了模式验证:缺少表 [游戏]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这可能是重复的:架构验证:缺少表 [hibernate_sequences] 但我可以'想办法.

I think it may be possible dupplicate of this: Schema-validation: missing table [hibernate_sequences] but I can't figure it out.

所以在我的 application.properties 文件中我有这个选项:spring.jpa.hibernate.ddl-auto=validate 并且我收到这个错误:

So in my application.properties file I have this option: spring.jpa.hibernate.ddl-auto=validate and I receive this error:

架构验证:缺少表 [游戏]

为什么我会收到这个?

这是我的 Game 类和 User 类:

Here is my Game class and 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 validates that the entities are compatible against the target, to a degree it's not foolproof. Anyway, whatever database you are trying to validate against does not have a table called game in which to store the entities.

这个答案更详细地介绍了 validate 的作用.

This answer goes into more detail about what validate does.

休眠 - hibernate.hbm2ddl.auto = validate

具体来说,

检查表、列、id生成器的存在

checks the presence of tables, columns, id generators

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

Without knowing your database/expectations (are you expecting it to be created, or using Flyway/Liquibase to create/update the database etc.) I can't answer if validate is correct for your use case.

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

You could try create-drop to create and drop the table on startup/shutdown, but this isn't a solution for any production control over a database.

这篇关于模式验证:缺少表 [游戏]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆