2022-05-24-TIL

Today I Learned

JPA 연관관계

  • https://cjw-awdsd.tistory.com/47

JPA 복합키 매핑, @Embedded vs @IdClass

  • https://www.baeldung.com/spring-jpa-embedded-method-parameters
  • https://velog.io/@cham/JPA-%EB%B3%B5%ED%95%A9-%ED%82%A4-%EB%A7%A4%ED%95%91%ED%95%98%EB%8A%94-%EB%B2%95
  • https://www.baeldung.com/jpa-composite-primary-keys

JPA FK 중복에러

  • https://parksrazor.tistory.com/218

JPA Join Table

JPA에서 조인 테이블을 통해서 연관관계를 매핑하려고 할 때, id만 갖고있는 테이블이면 @JoinTable로 매핑하고 별도의 엔티티는 정의하지 않아도 된다. 하지만 연관관계 테이블(조인 테이블)에 여러가지 필드를 포함하고 있는 경우에는 엔티티로 선언을 할 필요가 있는데, 이 때 @JoinTable로 매핑해두면 중복 키 에러가 발생하여 실행이 안된다.

@JoinTable(
    name = "post_comment_ref",
    joinColumns = @JoinColumn(name = "post_id"),
    inverseJoinColumns = @JoinColumn(name = "post_comment_id")
)
private List<PostComment> comments = new ArrayList<>();
  • https://parkhyeokjin.github.io/jpa/2019/10/28/JPA-chap6.html
  • https://stackoverflow.com/questions/5478328/in-which-case-do-you-use-the-jpa-jointable-annotation
  • https://velog.io/@sa1341/JPA-%EC%A1%B0%EC%9D%B8-%EC%BB%AC%EB%9F%BC-%EB%B0%8F-%EC%A1%B0%EC%9D%B8-%ED%85%8C%EC%9D%B4%EB%B8%94-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0
  • https://stackoverflow.com/questions/61510176/duplicatemappingexception-table-contains-physical-column-name-referred-to
  • https://docs.oracle.com/javaee/6/tutorial/doc/bnbqa.html#bnbqf
  • https://www.baeldung.com/hibernate-many-to-many

One to One

  • https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/one-to-one-join-table.html
  • https://stackoverflow.com/questions/32317162/why-does-my-onetoone-mapping-through-a-jointable-not-work
  • http://www.java2s.com/Tutorials/Java/JPA/0720__JPA_OneToOne_Join_Column.htm
  • https://www.baeldung.com/jpa-one-to-one
  • https://stackoverflow.com/questions/39033485/one-to-one-broken-column-mapping-for-id-in-jpa