소스 코드
package com.example.assignment.Domain;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.annotation.CreatedDate;
import javax.persistence.*;
import java.time.LocalDateTime;
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "members")
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 30)
private String username;
@Column(nullable = false,length = 100)
private String password;
@Column(nullable = false,length = 50)
private String email;
@ColumnDefault("user_role")
private String role;
@CreatedDate
private LocalDateTime localDateTime;
}
오류 구문
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 'user_role,
하루종일 해결을 해보려고 한 Entity 생성에 대한 답이 @ColumnDefault("user_role") 구문 때문이었다. 혹시나 mysql의 예약어가 포함된건가 하여 aaaa로도 하고 ddqs같은 전혀 연관성 없는 이름을 넣었음에도 오류가 발생하였다.결론적으로는 어노테이션을 잘못 사용한 탓에 발생한 오류였고 해당 오류를 수정하니 아래와 같이 Table이 잘 생성되었다.
'Spring' 카테고리의 다른 글
Spring Boot MySQL 연결하기 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) (0) | 2024.04.20 |
---|---|
레이스 컨디션이란? (0) | 2024.04.18 |
Spring Security Request method 'GET' not supported 에러 (0) | 2023.01.27 |
@NoArgsConstructor(access = AccessLevel.PROTECTED) (0) | 2023.01.26 |
Spring boot Mysql dbeaver연동 삽질 (0) | 2023.01.17 |