반응형
Oracle Sequence 생성
CREATE SEQUENCE YOUR_SEQ_NAME
START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;
Entity 설정
더보기
import jakarta.persistence.*
import java.time.LocalDateTime
@Entity
@Table(name = "YOUR_TABLE_NAME")
data class YourEntity(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "your_seq_generator")
@SequenceGenerator(
name = "your_seq_generator", // generator 이름
sequenceName = "YOUR_SEQ_NAME", // Oracle에 생성된 시퀀스 이름
allocationSize = 1 // Oracle은 보통 1로 설정
)
val id: Long? = null,
@Column(name = "name")
val name: String,
@Column(name = "created_at")
val createdAt: LocalDateTime = LocalDateTime.now()
)
JPA에서 entity.id = null 로 .save() 하면, id 자동 증가 되어 등록 됨.
반응형
'skill > Java.Kotlin' 카테고리의 다른 글
Kotlin UTC (3) | 2025.06.12 |
---|---|
SpringBoot 등록자, 등록일, 수정자, 수정일 자동 삽입 (0) | 2025.06.12 |
JPA 에러 JpaSystemException, IdentifierGenerationException (0) | 2024.01.12 |
springboot @Scheduler 다중 서버에서 한번만 실행 : shedlock (1) | 2023.11.21 |
[springboot] yml 과 Properties 설정 (1) | 2023.11.21 |