Spring Data-Jpa

H2 DB Error executing DDL create table "CommandAcceptanceException"


Spring Datafication 2022. 9. 17. 00:54

H2 DB Error executing DDL create table "CommandAcceptanceException"

This is a command error in the Java Persistence API(JPA).
It is caused when entities have clashing names with the already existing words in H2 DB.

So let's consider creating an entity

@Entity(name = "FastCars_tbl")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class FasCars {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private long id;
    private String brand, model, color, registerNumber;
    private int year, price;
    @Column(name="explanation", nullable=false, length=215)
    private String description;
}

This entity creation at runtime when executing the query

create table fast_cars_tbl (id bigint not null, brand varchar(255), color varchar(255), explanation varchar(215) not null, model varchar(255), price integer not null, register_number varchar(255), year integer not null, primary key (id))

Throws an error.

Cause

A bad naming which clashes with the already existing keywords of H2
and could be caused by bad constructors of entity.

Origin of error


Run time error which can only be detected or solved if one already know all the forbidden keywords in entity creation.

Solution


We simply change year to cYear.
Because year is already in the H2 DB keywords.
So this was a cause to the CommandAcceptanceException.

반응형