강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

const.takeo님의 프로필 이미지
const.takeo

작성한 질문수

자바 ORM 표준 JPA 프로그래밍 - 기본편

기본 키 매핑

시퀀스 전략 질문드립니다.

작성

·

340

0

시퀀스 전략 질문드립니다.

1. 시퀀스 전략은 하나의 트랜잭션 안에서만 유효하다.

  • DB시퀀스를 51로 확보해두고 메모리에서 1부터 차례대로 사용하는 예

2. 필연적으로 id값의 공백이 발생하게 된다.

제가 이해한게 맞을까요?

퀴즈

A class using the `@Entity` annotation for JPA mapping must basically meet these important conditions: 1. It must have a no-argument constructor (default constructor). 2. It must have a field representing the primary key, usually marked with the `@Id` annotation. 3. The class itself cannot be `final`. 4. It cannot be an `enum` or an `interface`.

All fields must be public

must be a final class

Must have a public or protected default constructor

must include at least one static method

답변 1

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. const.takeo님

시퀀스 전략은 트랜잭션과는 무관합니다. 왜냐하면 트랜잭션이 실패하면 해당 시퀀스를 버려야 하기 때문이에요. 해당 시퀀스가 롤백 된다면... 새로 생성된 키가 과거 문제가 있어서 롤백되었던 키와 같은 키가 될 수 있습니다.

그래서 시퀀스는 조회하는  순간 1이 증가합니다. 그리고 트랜잭션과 무관하게 동작합니다.

그리고 id 값의 공백은 발생할 수 있습니다.

감사합니다.

const.takeo님의 프로필 이미지
const.takeo

작성한 질문수

질문하기