Note to Self:
If you are using PostgreSQL with Hibernate and got this error, make sure that the entity names are not in the PostgreSQL’s reserved keywords. So the table name(or the Entity name) “User” is going to give the error in the title!
Posted in:
Programming
Very useful. Let me share an workaround if you still want your entity/table to be named User.
Background: Hibernate creates a query like this:
select
user0_.id as id0_,
user0_.first_name as first2_0_,
user0_.last_name as last3_0_,
from
user user0_
This user in the from clause messes the things.
The work around is to specify your schema. Can be done in two ways
1. By specifying the schema in the table in the @Table annotation. In case of schema public, will look like this.
@Entity
@Table(schema=”public”, name = “user”)
2. By specifying the schema in the schema in the persistence.xml
This will crate a query that works:
select
user0_.id as id0_,
user0_.first_name as first2_0_,
user0_.last_name as last3_0_,
from
public.user user0_
Note that public.user
Thanks,
Not just a note to yourself, also to me.
Thanks,
Not just a note to yourself, also to me.