상속관계 Entity간 조인
492
작성한 질문수 1
안녕하세요.
고객 테이블을 상속관계를 이용하여 아래와 같이 설계를 하였습니다.(개인고객, 법인고객)
@Entity
@Getter @Setter
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CUSTOMER_TYPE")
public abstract class Customer extends BaseEntity {
@Id @GeneratedValue
@Column(name = "CUSTOMER_ID")
private Long id;
private String name;
@Embedded
private Address address;
private int lineCount;
@Column(name = "CUSTOMER_TYPE", insertable = false, updatable = false)
private String customerType;
}
@Entity
@Getter @Setter
@DiscriminatorValue("COMPANY")
public class CompanyCustomer extends Customer{
private String vatCode;
private String owner;
private String companyPhone;
}
@Entity
@Getter @Setter
@DiscriminatorValue("PERSON")
public class PersonalCustomer extends Customer {
private String jumin;
private String handPhone;
}
그리고 고객을 위한 DTO도 생성을 했습니다.
@Data
public class CustomerDto {
@QueryProjection
public CustomerDto(Long id, String name, int lineCount, Address address, String customerType, String jumin, String handPhone, String vatCode, String owner, String companyPhone) {
this.id = id;
this.name = name;
this.lineCount = lineCount;
this.address = address;
this.customerType = customerType;
this.jumin = jumin;
this.handPhone = handPhone;
this.vatCode = vatCode;
this.owner = owner;
this.companyPhone = companyPhone;
}
private Long id;
private String name;
private int lineCount;
private Address address;
private String customerType;
private String jumin;
private String handPhone;
private String vatCode;
private String owner;
private String companyPhone;
}
위 상태에서 querydsl를 이용해서 DTO에 Data를 넣기 위해서는 querydsl을 어떻게 생성해야 할꺄요?
실제로 sql query는
select
customer0_.customer_id as customer2_2_,
customer0_.crt_dt as crt_dt3_2_,
customer0_.updt_dt as updt_dt4_2_,
customer0_.city as city5_2_,
customer0_.street as street6_2_,
customer0_.zipcode as zipcode7_2_,
customer0_.customer_type as customer1_2_,
customer0_.line_count as line_cou8_2_,
customer0_.name as name9_2_,
customer0_.company_phone as company10_2_,
customer0_.owner as owner11_2_,
customer0_.vat_code as vat_cod12_2_,
customer0_.hand_phone as hand_ph13_2_,
customer0_.jumin as jumin14_2_
from
customer customer0_
위와 같이 발생하는 방법으로 알고 싶습니다.
감사합니다.
답변 1
0
안녕하세요. 김문근님
이 경우는 엔티티로 조회하신 다음에 엔티티를 직접 DTO로 직접 변환하셔야 합니다.
그게 아니라면 네이티브 SQL을 사용하셔야 합니다.
만약 비즈니스 로직에 큰 차이가 없고, 단순히 데이터의 차이만 있다면, 상속 관계를 사용하지 말고, 한 테이블에 합치는 것을 권장합니다.
감사합니다.
SpringBoot 4.X에서의 Querydsl 설정
0
87
2
querydsl 오픈소스에 대한 질문
0
72
1
예제에서의 카운트 쿼리에서 join문과 where문은 필요없지 않나요?
0
108
1
Querydsl 6.X버전에 대해서 어떻게 생각하시나요?
0
317
2
여러 테이블 조인하여 통계치를 구하고자 할 때 어떤 방법이 더 효율적일까요
1
69
1
fetchResults()는 더이상 권장되지 않는다는데 맞나요?
0
160
1
querydsl sum() 메서드 없어요.
0
158
2
build 디렉터리 생성
0
136
2
자바 ORM 표준 JPA 프로그래밍 - 기본편 듣고 바로 학습해도 괜찮을까요?
0
114
2
현재 Querydsl에서 from절 서브쿼리를 지원하나요?
0
90
1
오타 제보 드립니다.
0
71
2
벌크 연산과 flush, clear
0
76
1
Run As Intellij 로 변경시 Q타입 import 불가
0
87
1
QHello import하기 문제 발생
0
147
2
등록된 함수 보는법(H2Dialect) 질문
0
68
2
5.0부터 Querydsl은 향후 fetchCount() , fetchResult() 를 지원하지 않기로 결정했다고 하는데 이에 맞는 강의
1
195
2
[환경설정 PDF 부트 3.0이후 설명 질문] build.gradle에 compileQuerydsl을 정의하지 않은 상태에서 Gradle->Tasks->other->compileQuerydsl을 클릭하라고 하는 이유가 무엇인가요??
1
200
1
querydsl 설정 문제
0
222
2
quey dsl 설정부분
0
158
2
count 쿼리 관련 질문입니다!
0
75
1
stringtemplate를 이용하여 where절 검색 방법 질문 드립니다.
0
89
1
답변부탁드리겠습니다.
0
89
2
(OrderSpecifier)관련 내용 어디있을가요
0
65
1
중급문법 벌크연산에서
0
81
2





