javaoracle-databasespring-bootcode-first

Spring boot "oracle.jdbc.OracleDatabaseException: ORA-00904: invalid identifier" Error while creating table


In spring boot, I create tables of the database using the Code-First approach. then while running the application, the result for one of tables shows this error:

WARN  o.h.t.s.i.ExceptionHandlerLoggedImpl.handleException - GenerationTarget encountered exception accepting command : Error executing DDL "alter table statistic add date timestamp" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceExcepti
on: Error executing DDL "alter table statistic add date timestamp" via JDBC Statement]

oracle.jdbc.OracleDatabaseException: ORA-00904: : invalid identifier

The class entity is as follow:

@Entity
@Table(name = "statistic")
public class Statistic {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String title;
    private Long value;
    private Date date;
    private String unit;


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Long getValue() {
        return value;
    }

    public void setValue(Long value) {
        this.value = value;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }
}

Does anyone know where is the problem?


Solution

  • This is wrong:

    alter table statistic add date timestamp
                              ----
                              this
    

    date is a reserved word for Oracle datatype. Change column name to something else, e.g. datum, c_date, statistic_date, ... and then run

    alter table statistic add datum timestamp