2017-06-11 76 views
1

我認爲這可能是這可能dupplicate: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

validate驗證該實體是針對目標相兼容,在一定程度上它是不是萬無一失的。總之,無論你的數據庫試圖驗證對不具有表叫在其中存儲實體game

這個答案進入什麼validate做更多的細節。

Hibernate - hibernate.hbm2ddl.auto = validate

具體而言,

checks the presence of tables, columns, id generators

不知道你的數據庫/預期(你希望它來創建或使用遷飛/ Liquibase創建/更新數據庫等),我可以」如果validate對於您的用例正確,請回答。

你可以嘗試create-drop創建和刪除的啓動/關閉表,但是這不是在數據庫中的任何生產控制的解決方案。

+0

我解決了問題,並創建表[遊戲],現在它工作正常。 – Rares

+0

您可以檢查這個問題PLZ? https://stackoverflow.com/q/44485076/7947794 – Rares