Open MinJunKweon opened 1 year ago
한 번도 사용해본적은 없지만, JPA에서 상속을 지원해주는 애노테이션이 있다고 한다.
@MappedSuperClass : 좋은 기능이긴 하나, 실무에서 쓰긴 조금 애매할 수 있음.
복합키 사용을 위해 JPA에선 두 가지 방법을 제공해준다. 하나는 @IdClass
이고, 다른 하나는 EmbeddedId
이다. ( 우리팀에선 후자를 주로 쓰고 있음 )
개인적으로 책을 읽어보니, IdClass
보다는 EmbeddedId
가 조금 더 명확해보여서 마음에 든다.
저자 또한 둘은 각각 장,단점이 있으니 취향에 맞게 일관성
있게 사용할 것을 추천하고 있다.
@EmbeddedId
오늘 사이드프로젝트에 써봤는데, 한 뎁스 들어가는게 불편해서 @IdClass
로 다시 바꿈구현 전략
Join 전략: table은 분리하되 PK로 Join을 하고, DType으로 구분한다.
→ 사실 조인 이나 insert query 2번 나가는 건 그렇게 성능 저하가 일어나지는 않음. 복잡한 게 더 문제..
단일 테이블 전략: 하나의 테이블에 모든 요소를 넣는다
구현 클래스마다 테이블 전략: 모든 컬럼을 테이블이 각각 다 가진다.
끄적끄적
@MappedSuperclass
는 생성시간, 수정시간 같은 Audit을 위한 필드를 강제하기 위해 사용하면 좋다고 생각함