Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

개발자되기 프로젝트

id 생성전략 변경 본문

Project/블로그 게시판 만들기

id 생성전략 변경

Seung__ 2021. 10. 22. 11:51

1. 원인


  • 지금 구조에서 가장 큰 문제가 있다.
  • post 번호가 연속적으로 생서이 안된다.
  • 글번호(순서)는 postID를 활용한다.
  • ID 생성 규직을, comment, post, member가 공유해서 발생한 문제이다.
  • 현재는 @GeneratedValue에 전략을 지정하지 않은 상태이다.
  • 지정하지 않으면 AUTO가 적용된다.
    • 각 DB에 적합한 값을 넘겨준다.
    • DB 의존성 없음.
Indicates that the persistence provider should pick an appropriate strategy for the particular database.
The AUTO generation strategy may expect a database resource to exist, or it may attempt to create one.
A vendor may provide documentation on how to create such resources in the event that
it does not support schema generation or cannot create the schema resource at runtim

 

3,6,8,10,12....

 

 

 

2. 해결


  • @GeneratedValue에 전략은 Identity지정하면 간단히 해결된다.
 @GeneratedValue(strategy = GenerationType.IDENTITY)
  • Identity전략 
    • 주로 MySQL에서 사용하며 DB의존적임
    • Transaction이 종료되기 전에 Insert문이 실행되어 ID값을 받아옴.
Indicates that the persistence provider must assign primary keys for the entity using a database identity column.
  • 결과

 

 

3. GitHub: 211022 change Strategy of Id Generation


 

GitHub - bsh6463/blog

Contribute to bsh6463/blog development by creating an account on GitHub.

github.com

 

'Project > 블로그 게시판 만들기' 카테고리의 다른 글

WebApplication 배포, Heroku  (0) 2021.10.22
블로그 만들기 결과  (0) 2021.10.22
Exception Resolver, 예외 페이지  (0) 2021.10.21
Paging처리  (0) 2021.10.21
비로그인 사용자 글 등록/삭제/수정 test  (0) 2021.10.19
Comments