PSQLException: ERROR: syntax error at or near PSQLException: ERROR: syntax error at or near postgresql postgresql

PSQLException: ERROR: syntax error at or near


Your entity maps across to a table name that is an SQL reserved keyword (User). Sadly for you, your chosen JPA provider does not automatically quote the table name identifier, and so you get exceptions when referring to the table.

Solution is either to quote the table name yourself in the @Table annotation, or change the table name to not be a reserved keyword. Alternatively use a JPA provider that auto-quotes such reserved keywords for you (e.g DataNucleus)


Solution 1: As Pascal mentioned, you have to escape the table name with backslash like:

@Entity@Table(name="\"User\"")public class User {    ...}

Solution 2: Rename your table's anme with another name (Users)

@Entity@Table(name="Users")public class User {    ...}

Solution 3: Add a suffix to the table's name:

@Entity@Table(name="APP_User")public class User {    ...}

Solution 4: Change the entity name, e.g. ApplicationUser

@Entitypublic class ApplicationUser {    ...}

The reason

PostgreSQL as some reserved SQL Key Words. For example: ABORT, ALL, ARRAY, CACHE, CUBE, USER, ... Those tokens are in the SQL standard or specific to PostgreSQL


Use the @Table annotation or change your class name from User to something else as User is a reserved keyword in sql.