Skip to content

Conversation

@corjqnrl
Copy link

  • 5단계: 데이터베이스 적용하기
  • 6단계: 데이터 조회하기
  • 7단계: 데이터 추가/삭제 하기

Copy link

@juanxiu juanxiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~

throw new RuntimeException("Failed to insert reservation");
}

Long generatedId = jdbcTemplate.queryForObject("SELECT MAX(id) FROM reservation", Long.class);
Copy link

@juanxiu juanxiu Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 SELECT 구문이 원자성을 보장하는지 고민해봐야할 것 같습니다. 만약 두 개의 INSERT 문이 연속적으로 실행되고, 그 다음에 SELECT 로 조회한다면 먼저 들어간 레코드의 id가 하나 증가한 채로 조회될 것 같아요. 또는 삭제된 레코드 때문에 MAX가 실제 생성된 ID와 다를 수 있겠네요. 트랜잭션의 특징을 더 알고 싶다면 이 글을 보는 것도 좋을 것 같아요!

그리고 JDBC 의 keyholder 를 사용해서 리팩터링하는 게 좋을 것 같습니다. 이 글을 참고해보실래요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants