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

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

问题描述

我认为这可能是重复的:模式验证:缺少表[hibernate_sequences] ,但我可以. t弄清楚.

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:

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;
    }
}

推荐答案

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天全站免登陆