Recent Posts
Recent Comments
HEROJOON 블로그(히로블)
JPA Table에 Index 설정하기 본문
반응형
목표
JPA Table에 Index 설정하기
- 단일 Index 지정
- 복합 Index 지정
- Unique Index 지정
환경
- Framework : Spring Boot 2.6.7
- Build : Gradle 6.9.2
- JDK : JDK11
해보기
● Index 추가 전 JPA Entity
● Index 추가 후 JPA Entity
1. Index 추가 방법 (단일 Index 추가할 경우)
@Table(name = "MEMBER", indexes = @Index(name = "idx__email__birthday", columnList = "email, birthday"))
2. Index 추가 방법 (Index를 여러개 추가 할 경우)
@Table(name = "MEMBER", indexes = {
@Index(name = "idx__email__birthday", columnList = "email, birthday"),
@Index(name = "idx__name__age", columnList = "name, age")
})
3. Unique Index 추가 방법
unique = true 옵션을 넣어주면 Unique Index로 생성된다.
default는 false이기 때문에 unique 옵션을 넣지 않으면 기본 Index로 생성된다.
@Table(name = "MEMBER", indexes = {
@Index(name = "idx__email__birthday", columnList = "email, birthday"), // index (unique = false (default))
@Index(name = "idx__name__age", columnList = "name, age"), // index (unique = false (default))
@Index(name = "idx__unique__nickname", columnList = "nickname", unique = true) // unique index
})
반응형
'JPA' 카테고리의 다른 글
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL 오류 (0) | 2022.08.30 |
---|---|
Spring Boot에서 JPA 사용하기 (0) | 2022.04.22 |
Comments