JPA 기본키(PK) 매핑

hyunwoo·2023년 2월 6일
0

Spring (fastcampus)

목록 보기
18/27

출처: https://gmlwjd9405.github.io/2019/08/12/primary-key-mapping.html

기본 키 맵핑

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

기본 키 생성을 데이터베이스에 위임

즉, id 값을 null로 하면 DB가 알아서 AUTO_INCREMENT 해준다.
Ex) MySQL, PostgreSQL, SQL Server DB2 등

. Auto increment 란?

테이블 컬럼에 auto_increment를 설정하게 되면, 데이터가 삽입 되는 순간 자동으로 증가 됩니다. 데이터 타입은 INT, BIGINT를 주로 많이 사용 합니다.

출처: https://estenpark.tistory.com/386

0개의 댓글