3

My DB contain User table with same named fields in class User.

I still have a problem with @Column annotation: Intellij IDEA stresses the name of the column.

DBTable

    CREATE TABLE "user"
(
  email character varying,
  login character varying NOT NULL,
  password character varying NOT NULL,
  name character varying NOT NULL,
  id_user numeric NOT NULL,
  CONSTRAINT user_pkey PRIMARY KEY (login, password, id_user),
  CONSTRAINT user_email_key UNIQUE (email)
)

Why this exception of syntax?? I have the same named table

root cause

org.postgresql.util.PSQLException: ERROR: syntax error at or near "User"
  Position: 13
    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:365)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
    org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3067)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
    org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
    org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
    org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
    org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
    org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
    org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
    com.classes.UserDB.registerUser(UserDB.java:17)
    com.servlets.Registration.doPost(Registration.java:29)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

User class

package com.DB;

import javax.persistence.*;

@Entity
public class User {

    @Lob
    private String email;
    @Lob
    private String login;
    @Lob
    private String password;
    @Lob
    private String name;

    @Id
    @GeneratedValue
    private int id_user;

    public int getId_user() {
        return id_user;
    }

    public void setId_user(int id_user) {
        this.id_user = id_user;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public User getUserFromBase(){
        return this;
    }
}

How it resolve?

2
  • Maybe a wrong query (syntax error) near UserDB at line 17? Commented Dec 28, 2014 at 11:29
  • I've edited. No, doesn't work Commented Dec 28, 2014 at 11:35

2 Answers 2

2

user is a reserved word and table with name user can not be created.

try adding @Table(name="USER_TABLE") after @Entity to change table name.

sorry haven`t read that carefully. it seems u already have a table named "USER". that's the problem with oracle

Sign up to request clarification or add additional context in comments.

1 Comment

Or use backticks if you still want to use the reserved keyword: @Table(name="`user`").
0

"user" is a reserved word in PostgreSQL and it's usually not a good idea use reserved words for tables or columns.

If you want to save yourself a lot of trouble use a different name. users, user_acount. also would change the class name for the same as table.

put @Table(name="USERS") annotation:

@Entity
@Table(name="users")
public class Users {

}

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.