안녕하세요 영한님 @Setter를 뺏을 때 어떻게 하시는지 궁금해서 여쭤봅니다.
이번 강좌편 잘 들었습니다.
setter 쓰지않는게 좋다고 여러강좌 (jpa 웹앱, 이 강좌 값 타입 등등) 여러차례 강조해주셨는데요~
그럼 상속구조에서는 Item 에 있는 필드를 protected 로 잡고 가는게 맞는건가요?
상속구조에서는 어떤식으로 풀어가는게 관례인가요?
지금 당장은 아래처럼 풀어가는것밖에 생각이 안나서 여쭤봅니다!
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "dtype")
@Getter
@Setter
public abstract class Item {
@Id @GeneratedValue
@Column(name = "item_id")
private Long id;
protected String name;
protected int price;
protected int stockQuantity;
@Entity
@DiscriminatorValue("M")
@Getter
//@Setter
@NoArgsConstructor(access = PROTECTED)
public class Movie extends Item {
private String director;
private String actor;
@Builder
public Movie(String title, String director, String actor, int price, int stockQuantity) {
this.name = title;
this.director = director;
this.actor = actor;
this.price = price;
this.stockQuantity = stockQuantity;
}
@SpringBootTest @Transactional
@Rollback(false)
public class InheritenceTest {
@Autowired EntityManager entityManager;
@Test
public void di(){
Movie movie = new Movie("Back to the future","xxx","yyy",5000,10);
entityManager.persist(movie);
}
답변 1
실무 조언 관련 질문입니다.
0
39
1
H2데이터베이스 파일 생성
0
48
2
서브쿼리 강의에서 ALL 예시 관련 질문드립니다.
0
49
2
수정또는 삭제시 영속성 엔티티에 값이 무조건 있어야 하나요?
0
46
1
JPQL 메소드와 락
0
49
1
Delivery @OneToOne
0
55
1
17강 4~5분대 테이블 값 조회가 안됩니다.
0
85
2
UnsupportedOperationException 발생
0
80
3
H2 Database 연결이 안됩니다.
0
87
2
연관관계 매핑 질문드립니다.
0
79
2
h2데이터베이스 실행오류
0
103
2
persistence.xml
0
101
2
양방향 연관관계에서 연관관계의 주인(mappedBy)을 왜 꼭 정해야 하나요?
0
76
1
영속성 컨텍스트
0
61
1
JPA 프록시
0
87
1
Native Query와 MyBatis
0
62
1
영속성 컨텍스트는 어떤 메모리에 저장되는건가요?
0
81
1
임베디드 타입 예시 코드 관련 질문
0
110
3
명시적 조인에서 별칭을 주면 왜 객체에 접근할 수 있나요
0
89
3
인텔리제이 패키지 커서 단축키 질문
0
104
2
혹시 현재는 ID 데이터 타입이 String이면 안되나요?
0
134
1
양방향 연관관계 시 연관관계 주인을 설정하는 이유
0
67
1
임베디드 타입과 MappedSuperClass의 차이점이 궁금합니다.
0
95
1
데이터베이스가 초기화되는 것 같아요
1
173
2





