관계에 대한 질문이 있습니다
234
작성한 질문수 1
안녕하세요. 강의 잘 보고 있습니다~
강의 에서 설명된 기본 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
spring boot 2.7.13-SNAPSHOT trace 소문자 로그 안나옴
0
533
1
<스프링 데이터 Common: 기본 리포지토리 커스터마이징> 에 대한 질문
0
392
1
comment table에서 저장될떄 왜 id값이 2부터저장이되는건가요?
0
407
1
@EnableJpaRepositories 설정을 스프링부트가 어디에서 자동설정하나요?
0
451
0
PersistenceContext 관련 질문드립니다.
0
335
1
지금(Eager), 나중에(Lazy)의 의미를 모르겠습니다
0
338
1
transaction 구간이 길어질 경우의 처리방법 문의드립니다.
0
905
1
docker postgres
0
293
1
Multiple DataSource 사용 시 transaction 관련 질문 드립니다.
0
2908
1
entity 중 null이 아닌 필드만 update 할 방법이 있을까요?
0
1191
1
Eager 모드일 경우, join을 inner join으로 바꾸는 법이 있을까요?
0
385
1
엔티티를 상속받는 DTO가 일반적인가요?
1
1847
1
커스텀 타입 클래스를 String 타입 처럼 이용해 쿼리하는 방법에 대해 질문하고 싶습니다.
0
339
1
연관관계 매핑 어떤식으로 해야될지 감이 안잡힙니다.
0
566
4
EntityManager 주입시 Annotation관련 질문드립니다.
0
565
1
클래스 기반 프로젝션 사용 관련 질문
0
560
1
save 메서드 질문드립니다.
0
258
1
복잡한 통계쿼리도 JPA로 가능한가요?
2
5593
1
find 와 get의 차이가 무엇인가요?
0
890
1
실무에서 JPA 할 때 FK로 개발할때 연관관계를 꼭 맺어주어야 하나요?
0
999
1
\dt Did not find any relations.
0
481
1
소스코드는 어디서 볼 수 있을까요?
1
287
1
table 생성과 select 문에 대한 질문
0
174
1
스프링 데이터 RepositoryTest 관련 질문
0
2173
2





