skip to Main Content

I’m using Spring boot, and I Run this model.

package com.example.demo.Models;

import jakarta.persistence.*;

@Entity
@Table(name = "user")
public class UserModel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = true)
    private Long id;
    private String name;
    private String email;
    private Integer priority;
   
    /* Here are all the setters and getters*/
}

application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/dbdemo
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update

Everything fine with Java.

Process finished with exit code 0

But in the console of my docker image of Postgres I get the following error:

ERROR:  syntax error at or near "user" at character 14
STATEMENT: create table user(id bigserial not null, email varchar(255), name varchar(255), priority integer, primary key (id))

I’m not sure how to solve it, I’d appreciate any help.

3

Answers


  1. create table public.user ( id serial not null, 
                   email varchar(255), 
                   name varchar(255), 
                   priority integer, 
                   primary key (id))
    

    add the schema name before the table name

    enter image description here

    Login or Signup to reply.
  2. You need to specify the schema name in table and id fields like this:

    @Table(name = "anomaly", schema = "schema_name")
    public class Anomaly {
    
    @Id
    @SequenceGenerator(name = "id",  allocationSize = 1, schema = "schema_name")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long anomalyId;
    
    Login or Signup to reply.
  3. user is a reserved word in Postgresql thats why it show an error
    use a different word like "users" "usersId".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search