-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
관계에 대한 질문이 있습니다
19.07.26 23:01 작성 조회수 140
0
안녕하세요. 강의 잘 보고 있습니다~
강의 에서 설명된 기본 1:다 관계에서 comment에서 @ManyToOne 와 더불어
@JoinColumn(name = "post_id”) 를 주게되면 어떻게 달라지는지요?
그리고 추가 적으로
@ManyToOne
@JoinColumn(name = "post_id”, insertable = false, updatable = false)
insertable, updatable을 false로 주는건 어떤 의미인지요?
감사합니다
========================================
@Entity
public class Post {
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private Set<Comment> comments = new HashSet<>();
}
@Entity
public class Comment {
…
@ManyToOne
private Post post;
}
========================================
@Entity
public class Post {
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private Set<Comment> comments = new HashSet<>();
}
@Entity
public class Comment {
…
@ManyToOne
@JoinColumn(name = "post_id”)
private Post post;
}
========================================
@Entity
public class Post {
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private Set<Comment> comments = new HashSet<>();
}
@Entity
public class Comment {
…
private Long post_id;
@ManyToOne
@JoinColumn(name = "post_id”, insertable = false, updatable = false)
private Post post;
}
답변을 작성해보세요.
0
백기선
지식공유자2019.07.30
외례키 컬럼 이름이나 속성을 설정하는 겁니다. 자세한건 @JoinColumn JavaDoc을 읽어보세요. 해당 문서에 insertable, updatable에 대한 설명도 있습니다.
https://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html
답변 1