Hibernate throws "ERROR: syntax error at or near". How to escape a column name?


#1

If I have a table with a column called ‘name’ when I try to add a new row i get this error:

Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into public.services (host, name, password, port, user, id) values ('service.host', 'service', 'password', 707, 'user', 9) was aborted: ERROR: syntax error at or near "user"

Hibernate: 5.2.17
PostgreSQL: 10.5


#2

You need to escape the name column:

    @Column(name="`user`")

Or you could set the hibernate.globally_quoted_identifiers configuration property to true.