Problem: I've a simple entity with id property, and I can't save it.
Exception:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at ...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "User"
Position: 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
at ...
Code:
@Entity
@Table(name = "User")
public class User {
@Id
@GeneratedValue
private long userId;
//getter & setter
public static void main(String[] args) {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
User user = new User();
session.persist(user);
session.getTransaction().commit();
session.close();
}
}
HQL:
Hibernate: create table User (userId int8 not null, primary key (userId))
Hibernate: create sequence hibernate_sequence
INFO: HHH000230: Schema export complete
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into User (userId) values (?)
WARN: SQL Error: 0, SQLState: 42601
ERROR: ERROR: syntax error at or near "User"
Position: 13