[fix] Java Spring Boot JPA SQLSyntaxErrorException: Encountered user at line 1 column 14


Spring Boot JPA with Derby Exception:
org.hibernate.tool.schema.spi.CommandAcceptanceException: 
Error executing DDL 
"create table user (user_name varchar(255) not null, user_email varchar(255), user_id varchar(255), 
primary key (user_name))" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase. 
accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "user" at line 1, column 14.
Caused by: org.apache.derby.iapi.error.StandardException: Syntax error: Encountered "user" at line 1, column 14.
Reason:

user is a reserved keyword, change the JPA Entity or make use of the @Table annotation and give a different name.

package com.example.demo;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "user_master") //eg. use of user_master
public class User { //or change this to something like UserEntity or UserMaster

    @Id
    private String userName;
    private String userId;
    private String userEmail;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }
}
Fix SQLSyntaxErrorException Spring Boot JPA
Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap