일단 시작.

[TIL] SQLSyntaxError ( 컬럼명 like 문제) 본문

STUDY/SpringBoot

[TIL] SQLSyntaxError ( 컬럼명 like 문제)

꾸양! 2023. 7. 14. 21:26

발생한 예외

create table posts (
id bigint not null auto_increment,
created_at datetime(6),
modified_at datetime(6),
contents varchar(255),
like bigint,
title varchar(255) not null,
user_id bigint,
primary key (id)
) engine=InnoDB" via JDBC
[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 'like bigint, title varchar(255) not null, user_id bigint,' at line 6]

원래 코드

@Column
private long like = postLikeList == null ? 0 : postLikeList.size();

자꾸 posts Entity가 안 만들어지길래 왜 그런지 살펴봤더니 포스트 좋아요의 column을 like로 해놓았더니 like는 MySQL의 예약어라 사용할 수 없는 컬럼이라 발생하는 문제였다. like 변수명 자체를 postLike로 바꿔서 해결.

수정코드

@Column
private long postLike = postLikeList == null ? 0 : postLikeList.size();