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

1

3 Answers 3

0

USER is a PostgreSQL reserved word. Rename the table

@Table(name="usertable")
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.