Home > Back-end >  Spring Jpa Repository crash on insert
Spring Jpa Repository crash on insert

Time:04-08

I'm trying to implement a repository for refresh JWT tokens and I can't save my token in postgresql.

My entity :

@Entity(name = "refreshtoken")
public class RefreshToken {
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE)
  private long id;

  @Column(nullable = false, unique = true)
  private String user;

  @Column(nullable = false, unique = true)
  private String token;

  @Column(nullable = false)
  private Instant expiryDate;

  public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

  public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

  public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

  public Instant getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Instant expiryDate) {
        this.expiryDate = expiryDate;
    }

The refresh token is initialised with the right values. The logs are

Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into refreshtoken (expiry_date, token, user, id) values (?, ?, ?, ?) 2022-04-08 11:17:22.475 ERROR 24272 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ERREUR: erreur de syntaxe sur ou prΦs de ½ user ╗ Positioná: 47 2022-04-08 11:17:22.483 DEBUG 24272 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Failed to complete request: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement 2022-04-08 11:17:22.497 ERROR 24272 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/xatis-web] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause

org.postgresql.util.PSQLException: ERREUR: erreur de syntaxe sur ou prΦs de ½ user ╗ Positioná: 47

I have spring.jpa.hibernate.ddl-auto= update I created refreshtoken table manualy but I also noticed that after it crashed, all field are created except user.

Any help would be welcome, thanks

CodePudding user response:

Like Manuel pointed out in the comment, user is a reserved word in postgresql

CodePudding user response:

"user" is a reserved keyword for Postgresql

  • Related