kimreik
kimreik

Reputation: 645

hibernate doesn't create tables postgresql

I know that there is a lot of similar questions here, but I've spent all day and didn't find a solution.

I'm using Hibernate 5.0.12 with PostgreSQL 9.6.3 in Spring Boot 1.5.4 project.

I have a simple user entity:

import javax.persistence.*;

@Entity
public class User {

    @Id
    @GeneratedValue
    @Column(nullable = false, updatable = false)
    private Long id;

    private String email;
    private String password;

    public Long getId() {       return id;  }
    public void setId(Long id)  {       this.id = id;   }
    public String getEmail() {      return email;   }
    public void setEmail(String email) {        this.email = email; }
    public String getPassword() {       return password;    }
    public void setPassword(String password) {      this.password = password; }
}

and application.properties:

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/my-db
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect
spring.hibernate.hbm2ddl.auto=create

logging.level.org.hibernate=DEBUG

Launching looks normal

hibernate logs

but table "user" hasn't been created.

With MySQL all works fine. Is there any issue with PostgreSQL? I'm new in it and just created DB like that:

createdb -h localhost -p 5432 -U postgres my-db password *********

and, after some tries to fix the issue, created schema in it:

CREATE SCHEMA "my-db" AUTHORIZATION postgres;

Upvotes: 2

Views: 2596

Answers (2)

Pathak
Pathak

Reputation: 193

As per your above code looks like you are missing @Table( name = "user" ) annotation.Can you please try once after adding this if that works?

Upvotes: -1

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

user is a reserved word in PostgreSQL. Use different table name, like users and put @Table(name = "users") annotation on top of your entity class.

Upvotes: 7

Related Questions