반응형
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'bigint not null auto_increment, ids varchar(255)
mysql과 jpa를 연결할 때, 이런 오류가 발생했다.
application.propertice 의 문제라고 생각했었지만, 아무리 검색해봐도 알 수가 없었다.
# 데이터베이스 연결 설정
spring.datasource.url=jdbc:mysql://localhost:3306/members
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hibernate 설정
#spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.show_sql = true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always
Member 엔티티를 살펴보니,
'index'가 MySQL 예약어로 사용되는 이름이라 테이블 생성 시 문제가 발생했던 것이었다.
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long index;
private String ids;
private String name;
private String phoneNumber;
}
필드명을 idx로 변경하니, 오류가 해결되고 MySQL 데이터베이스와 JPA가 정상적으로 연결되었다.