/
java.sql.SQLSyntaxErrorException DBNAME.hibernate_sequence' doesn't exist
java.sql.SQLSyntaxErrorException DBNAME.hibernate_sequence' doesn't exist
증상
Caused by: java.sql.SQLSyntaxErrorException: Table 'DBNAME.hibernate_sequence' doesn't exist
원인
Entity 의 ID 생성 strategy 가 GenerationType.AUTO 일 경우 hibernate는 자동으로 기본 sequence 정보 테이블인 hibernate_sequence
을 찾지만 없어서 발생
@Id @GeneratedValue(strategy = GenerationType.AUTO ) private Long id;
해결
hibernate_sequence 생성
drop 스키마후 application.properties 에 다음 내용 추가
spring.jpa.hibernate.ddl-auto=create
기존 스키마 삭제하면 데이타 날라가니까 주의
strategy 변경
수동으로 입력하도록 설정 변경
application.properties 에 다음 내용 추가
spring.jpa.hibernate.use-new-id-generator-mappings=false
Entity 객체 수정
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
sequence generator 사용
@Entity @Data @Table(name="Customers") @SequenceGenerator(name="my_seq_generator", sequenceName = "CUSTOMER_SEQUENCE" // DB Sequence Name //, initialValue = 1, // allocationSize = 50 ) public class Customer { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id;
Ref
, multiple selections available,
Related content
MySQL 테이블 및 데이타베이스 이름 대소문자 구분 설정
MySQL 테이블 및 데이타베이스 이름 대소문자 구분 설정
More like this
MyBatis 에서 insert 시 자동 생성키 사용하기
MyBatis 에서 insert 시 자동 생성키 사용하기
More like this
JPA MySQL 사용시 MyISAM 대신 InnoDB 사용하기
JPA MySQL 사용시 MyISAM 대신 InnoDB 사용하기
More like this
DB2 quick start reference
DB2 quick start reference
More like this
apache maven 버전별 필요 JDK
apache maven 버전별 필요 JDK
More like this
MySQL 1419 error - "You do not have the SUPER privilege and binary logging is enabled" 해결 방법
MySQL 1419 error - "You do not have the SUPER privilege and binary logging is enabled" 해결 방법
More like this