[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
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.