PSQLException: ERROR: syntax error at or near

前端 未结 2 1633
没有蜡笔的小新
没有蜡笔的小新 2021-02-14 03:00

I have what I thought was a straight forward relation in JPA. Looks like this. CompanyGroup:

@Entity
@Table
public class CompanyGroup implements Serializable {

         


        
2条回答
  •  野的像风
    2021-02-14 03:49

    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

    @Entity
    public 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

提交回复
热议问题