I have a model class that is mapped to a postgres database using hibernate. My model class is:
@Entity
@Table(name=\"USER\")
public class User {
@Id
@G
In PostgreSQL you have to specify the name of schema like so :
@Table(name="table_name", schema = "myapp")
^^^^^^^^^^^^^^^^
you got this error :
org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
because when you create a database in PostgreSQL, it create a default schema named public, so when you don't specify the name in the Entity
then Hibernate will check automatically in the public schema.
database
, schema
, tables
or columns
in PostgreSQL. Else you should to escape this names with quotes, and this can cause Syntax errors, so instead you can use :
@Table(name="table_name", schema = "schame_name")
^^^^^^^^^^ ^^^^^^^^^^^
+----------+-----------+----------+-----------+---------+
| Key Word |PostgreSQL |SQL:2003 | SQL:1999 | SQL-92 |
+----------+-----------+----------+-----------+---------+
| .... .... .... .... .... |
+----------+-----------+----------+-----------+---------+
| USER | reserved |reserved | reserved | reserved|
+----------+-----------+----------+-----------+---------+
UserEntity