QueryDSL join 및 subquery 및 case 문 사용 예시
case문 사용시 then 값은 enum값이 들지 않으니 String 으로 변환하여 사용한다. (querydsl 5.0)
(로직적으로 처리하자)
QTbEntity innerME = new QTbEntity("ime");
return queryFactory
.select(Projections.constructor(TbEntity.class, tbEntity.memberId, tbEntity.roleGroup, joinBEntity.commId, joinBEntity.enumA))
.from(tbEntity)
.leftJoin(joinAEntity).on(tbEntity.memberId.eq(joinAEntity.userId))
.leftJoin(joinBEntity).on(joinAEntity.commId.eq(joinBEntity.commId))
.where(tbEntity.roleGroup.ne(
JPAExpressions.select(new CaseBuilder()
.when(joinBEntity.enumA.eq(EnumA.EQ)).then("EQ_NAME")
.when(joinBEntity.enumA.eq(EnumA.DIFF)).then("DIFF_NAME")
.otherwise(tbEntity.roleGroup)
).from(innerME)
.leftJoin(joinAEntity).on(innerME.memberId.eq(joinAEntity.userId))
.leftJoin(joinBEntity).on(joinAEntity.commId.eq(joinBEntity.commId))
.where(innerME.memberId.eq(tbEntity.memberId))
)
);
'DB > hibernate' 카테고리의 다른 글
jpa hibernate naming physical-strategy 변경 (0) | 2022.10.07 |
---|---|
Hibernate Annotation 사용 (0) | 2012.07.26 |
Hibernate 쿼리 사용하는방법 (0) | 2012.07.24 |
HIbernate Annotation Default값주기. (0) | 2012.07.09 |
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here (0) | 2012.07.03 |