0

I'm getting this error when building a Javalin app that uses Hibernate with PostgreSQL. All the other tables are being created normally but this one gives me this error and I can't figure out why. I have seen this error but it happens when using the "user" as a table name may be sale is a postgre reserved name for an internal table.

2021-06-24T18:43:16.449969+00:00 app[web.1]: Jun 24, 2021 6:43:16 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
2021-06-24T18:43:16.449977+00:00 app[web.1]: WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table sale (id  serial not null, date date, user varchar(255), primary key (id))" via JDBC Statement
2021-06-24T18:43:16.449978+00:00 app[web.1]: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table sale (id  serial not null, date date, user varchar(255), primary key (id))" via JDBC Statement

The sale class hibernate annotations are like so:

@Entity
public class Sale implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column()
    private String user;
    @OneToMany(mappedBy = "sale")
    private Set<SoldProduct> products = new HashSet<>();
    @Column()
    private LocalDate date;

    public Sale(){
        this.date = LocalDate.now();
    }

    public Sale(String user, Set<SoldProduct> products){
        this.user = user;
        this.products = products;
        this.date = LocalDate.now();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public Set<SoldProduct> getProducts() {
        return products;
    }

    public void setProducts(Set<SoldProduct> products) {
        this.products = products;
    }

    public void addProduct(SoldProduct product){
        products.add(product);
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }
} 

I'm using java 11, hibernate 5.5.3 with PostgreSQL95Dialect on Heroku PostgreSQL

1 Answer 1

1

user column is a reserved word in postgres. Try to change it to something else.

Example:

@Column(name = "account_user")
private String user;
Sign up to request clarification or add additional context in comments.

1 Comment

That was the fix, never thought of it, thank you so much!!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.