0

I have got a strange problem, the method session.save() is throwing syntax exception "org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"" -look at the picture attached where you can see mapped table, hibernate query and it's parameters, all looks right, I have no idea where the problem can be. The column id_user has sequence which is autogenerated, and this value of the sequence is increases every time i try to call the save() method. The User mapped class:

package com.wily.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="user")
@SequenceGenerator(sequenceName="user_id_user_seq", name="userSequence")
public class User {

    @Id
    @Column(name="id_user")
    @GeneratedValue(generator="userSequence")
    private int id;

    @Column(name="username")
    private String username;

    @Column(name="password")
    private String password;

    @Column(name="email")
    private String email;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

}

So, the sequence is increasing, but user is not saved, the image: enter image description here

Pink
  • 431
  • 2
  • 9
  • 18
  • See also: [Hibernate saving User model to Postgres](http://stackoverflow.com/questions/3608420/hibernate-saving-user-model-to-postgres/3611916#3611916) – Reimeus Oct 04 '14 at 13:51

3 Answers3

0

USER is a PostgreSQL reserved word. Rename the table

@Table(name="usertable")
Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

I think you need to re-create table in DB and specify some another table name. Please check this link: How to configure Hibernate to put quotes around table names

Community
  • 1
  • 1
0

if rename didn't work try this problem is with data base.

<property name="hibernate.hbm2ddl.auto">update</property>

this will automatically create data base table on any db as per bean class. also check sequence you created is of same name or not.