Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema-validation: missing table [game]

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

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]

Why I am receiving this?

Here is my Game class and User class:

Game:

@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

User:

@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;
    }
}
like image 977
Rares Avatar asked Jun 11 '17 00:06

Rares


2 Answers

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.

This answer goes into more detail about what validate does.

Hibernate - hibernate.hbm2ddl.auto = validate

specifically,

checks the presence of tables, columns, id generators

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.

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.

like image 94
Darren Forsythe Avatar answered Sep 26 '22 01:09

Darren Forsythe


I got the same as I changed to Hibernate 5.4.0.Final. Either Hibernate suddenly has problems to recognize the default schema or the driver does not return the schema properly. I was able to bypass it by either adding the schema definition to the table definition.

@Table(name = "GAME", schema = "PUBLIC") 

or by adding a default schema in persistence.xml.

<property name="hibernate.default_schema" value="PUBLIC" />
like image 26
Bevor Avatar answered Sep 25 '22 01:09

Bevor