When I try to persist an entity called "user" with JPA/hibernate it does not work. The table is not created and it is because user is a reserved word in postgresql. Is there any way other than naming the table something else to make this work?
Out of the box, Hibernate works pretty well with PostgreSQL databases.
user is a pseudo-function keyword.
PostgreSQL: Find Users in PostgreSQL Answer: In PostgreSQL, there is a system table called pg_user. You can run a query against this system table that returns all of the Users that have been created in PostgreSQL as well as information about these Users.
To quote an identifier, use back ticks:
@Table(name="`users`")
See this example from Hibernate's test suite:
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/quote/User.java#L31
Hibernate will automatically detect it and convert to the appropriate quote for the database you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With