Error Logs๐Ÿพ

h2 DB ์—๋Ÿฌ

hae02y 2023. 7. 31. 21:20
๋ฐ˜์‘ํ˜•

error

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table [*]order (id bigint generated by default as identity, completed boolean not null, title varchar(255) not null, todo_order bigint not null, primary key (id))"; expected "identifier"; SQL statement: create table order (id bigint generated by default as identity, completed boolean not null, title varchar(255) not null, todo_order bigint not null, primary key (id)) [42001-214]

 

h2 DB ๋ฅผ ์ด์šฉํ•ด์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค๋˜์ค‘ ํ•ด๋‹น ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.

 

ํ…Œ์ด๋ธ”๋ช…์„ ์ง€์ •ํ•˜์ง€์•Š์œผ๋ฉด ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ–ˆ์ง€๋งŒ ํ…Œ์ด๋ธ”๋ช…์„ ์ง€์ •ํ•˜๊ฒŒ ๋˜๋ฉด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.

 

Solve

@Entity(name = "order")
@Getter
@Setter
public class Todo {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private String title;

    @Column(nullable = false)
    private Long todoOrder;

    @Column(nullable = false)
    private Boolean completed;
}

Entity์˜ ์ด๋ฆ„์„ order๋กœ ์ค€๊ฒƒ์ด ๋ฌธ์ œ์˜€๋‹ค.  "order"๋ผ๋Š” ๋‹จ์–ด๋Š” H2 ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์˜ˆ์•ฝ์–ด๋กœ ์‚ฌ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํ…Œ์ด๋ธ” ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ๋”ฐ๋ผ์„œ "order" ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๊ฒƒ์ด๋‹ค. ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์€

 

@Entity(name = "`order`")

์œ„์™€ ๊ฐ™์ด ๋ฐฑํ‹ฑ(`)์œผ๋กœ ๊ฐ์‹ธ์ฃผ๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ORDERํ…Œ์ด๋ธ”์ด ์ƒ์„ฑ๋˜๊ณ  ๋กœ๊ทธ์ƒ์˜ ์—๋Ÿฌ๋„ ์—†์–ด์ง„๋‹ค.

๋ฐ˜์‘ํ˜•