반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- netflix oss
- KAFKA
- QueryDSL
- ChannelPipeline
- docker
- MySQL
- vue.js
- RabbitMQ
- docker compose mysql
- jmeter
- docker-compose
- weblogic 10
- redis
- spring boot redis
- cassandra
- spring boot
- Redis Sentinel
- Docker Compose
- Netty
- mybatis
- WebLogic
- Airflow
- argo cd
- coalesce
- Hibernate
- spring cloud
- JPA
- Selenium
- grafana
- Spring Open Feign
Archives
- Today
- Total
IT.FARMER
QueryDsl Projection.bean Object로 조회 결과 받기 본문
반응형
DTO(Entity)를 처음 인자로 넣어 주고 Object와 mapping 되는 columl의 인자 값을 셋팅 한다.
create a Bean populating projection for the given type and expressions
Example
UserDTO dto = query.select(
Projections.bean(UserDTO.class, user.firstName, user.lastName));
@Embeddable / @EmbeddedId 로 멀티PK가 잡힌 경우엔
Projection.bean 사용시, alias 기능을 이용하여 Mapping 시켜 준다.
QAdGroupEntity qAdGroupEntity = QAdGroupEntity.adGroupEntity;
List<AdGroupEntity> adGroupEntities = jpaQueryFactory
.select(
Projections.bean(AdGroupEntity.class,
qAdGroupEntity.startTime.coalesce(new Date()).as("startTime"),
qAdGroupEntity.endTime.coalesce(new Date()).as("endTime"),
Projections.bean(qAdGroupEntity.adGroupEntityPK, qAdGroupEntity.adGroupEntityPK.campaignId,qAdGroupEntity.adGroupEntityPK.adGroupId,qAdGroupEntity.adGroupEntityPK.mediaId).as("adGroupEntityPK")
)
)
.from(QAdGroupEntity.adGroupEntity)
.where(QAdGroupEntity.adGroupEntity.adGroupEntityPK.campaignId.in(streamSupplierCampaignId.get().distinct().collect(Collectors.toList())))
.fetch();
fetchJoin 을 사용하여 Join된 모든 필드를 조회 한다.
중간에 fetchJoin을 해주지 않으면 조인 필드가 최종 검색 결과에 포함되지 않는다.
List<Tuple> tupleList = getJpaQuery().select(qRRequestInformationEntity, qRCampaignInfoEntity).from(qRRequestInformationEntity)
.join(qRCampaignInfoEntity)
.on(qRRequestInformationEntity.reportNumber.eq(qRCampaignInfoEntity.reportCampaignInfoPK.reportNumber))
.fetchJoin()
.where(qRCampaignInfoEntity.reportCampaignInfoPK.campaignId.eq(streamSupplierCampaignId.get().distinct().collect(Collectors.joining())))
.fetch();
반응형
'Spring > Spring Data JPA' 카테고리의 다른 글
QueryDsl Mysql DATE_ADD, ADDDATE (0) | 2020.05.26 |
---|---|
QueryDsl Null 인경우 다른 값으로 채우기 coalesce (0) | 2020.05.26 |
Hibernate/ spring jpa bulk save (0) | 2019.03.26 |
JPA Hibernate Bulk Save , Multi save (0) | 2019.01.03 |
JPA Hibernate Multi PK 주의점 (정적 내부 클레스) (0) | 2018.10.08 |