SpringBoot JPA in MySQL

30 Views Asked by At

I defined this class:

@Entity
@Table(name = "t_planets_tropical")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PlanetsTropical {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String desc;

}

but when I start the project I have this problem:

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc varchar(255), primary key (id)) engine=InnoDB' at line 1
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763)
    at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:78)
    ... 132 common frames omitted
1

There are 1 best solutions below

0
Simon Martinelli On BEST ANSWER

desc is a reserved SQL keyword and must not be used as a column name.

Either rename the attribute or us

@Column(name = "desc_column")
private String desc;

or similar to give the column another name.