강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

잉꼬님의 프로필 이미지
잉꼬

작성한 질문수

스프링 데이터 JPA

JPA 프로그래밍 4. 관계 맵핑

관계에 대한 질문이 있습니다

작성

·

231

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;

 

}

답변 1

0

백기선님의 프로필 이미지
백기선
지식공유자

외례키 컬럼 이름이나 속성을 설정하는 겁니다. 자세한건 @JoinColumn JavaDoc을 읽어보세요. 해당 문서에 insertable, updatable에 대한 설명도 있습니다.

https://docs.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html

잉꼬님의 프로필 이미지
잉꼬

작성한 질문수

질문하기