[내배캠/TIL(6/16)]JdbcSQLSyntaxErrorException ;expected "identifier" 오류 해결

손홍서·2022년 6월 16일
1

Spring

목록 보기
11/24

day38 TIL

JdbcSQLSyntaxErrorException ;expected "identifier" 해결

후딱 끝내려고 했는데 만난 오류...

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "\000a    create table comment (\000a       comment_idx bigint not null,\000a        created_at timestamp,\000a        updated_at timestamp,\000a        content varchar(255),\000a        depth integer,\000a        [*]group integer,\000a        order integer,\000a        parent integer,\000a        status varchar(255),\000a        post_idx bigint,\000a        user_idx bigint,\000a        primary key (comment_idx)\000a    )"; expected "identifier"; SQL statement:
@Entity
@Getter
@Setter
public class Comment extends BaseTimeEntity{
    @Id
    @GeneratedValue
    @Column(name="comment_idx")
    private Long id;
    private String content;
    private Integer depth;
    private Integer group;
    private Integer order;
    private Integer parent;

    @Enumerated(EnumType.STRING)
    private Status status;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="post_idx")
    private Post post;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="user_idx")
    private User user;

}

group이나 order같은 필드명도 sql의 ddl과 겹치면 오류가 난다.
이것도 모르고 테이블 명만 계속 바꾸면서 삽질...^^
이제 알았으니깐 괜찮다.

package withplanner.withplanner_api.domain;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;

@Entity
@Getter
@Setter
public class Comment extends BaseTimeEntity{
    @Id
    @GeneratedValue
    @Column(name="comment_idx")
    private Long id;
    private String content;
    private Integer depth;
    private Integer groups; //group xxx
    private Integer orders; //order xxx
    private Integer parent;

    @Enumerated(EnumType.STRING)
    private Status status;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="post_idx")
    private Post post;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="user_idx")
    private User user;

}

해결한 코드이다. order->orders, group->groups로 바꾸어 해결하였다.

@ElementCollection

번외로 리스트를 Entity 필드로 사용하고싶을때 쓰는 annotation이다.
즉, 값 타입 컬렉션을 매핑할 때 사용.

@ElementCollection
private List<String> days =new ArrayList<>();


이렇게 새로운 테이블이 하나 생긴다.
성능 이슈가 있을 수 있는데 생각을 해보아야겠다.

profile
Hello World!!

0개의 댓글