10

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;
    }
}
Jhonny007
  • 1,608
  • 1
  • 11
  • 32
Rares
  • 467
  • 1
  • 5
  • 19

6 Answers6

14

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.

kuporific
  • 9,655
  • 3
  • 39
  • 46
Darren Forsythe
  • 9,306
  • 3
  • 40
  • 47
9

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" />
Bevor
  • 8,006
  • 12
  • 71
  • 133
5

Don't forget permissions: GRANT select, insert, update, delete, alter ON table_name TO usr_name;

Makatun
  • 797
  • 8
  • 11
3

This error can appear while using spring boot with flywayDB. The issue might be due to the wrong naming convention of script files, which were used by flywayDB.

https://flywaydb.org/documentation/migrations#naming

Vineeth Bhaskaran
  • 2,021
  • 1
  • 27
  • 36
0

The SQL standard requires names stored in uppercase. If you named the table/fields in lowercase - JPA can automatically convert case to upper and trying to search names in this case, but write to logs in lower ¯\_(ツ)_/¯

Hett
  • 3,000
  • 2
  • 31
  • 47
0

Add this in application.yml:

spring:
  jpa:
    properties:
      hibernate:
        default_schema: game
Master Yi
  • 995
  • 4
  • 12
  • 31