@Entity 어노테이션 붙은 클래스 필드명을 따라 컬럼명 매칭룰을 적용

이를 커스텀으로 변경

CamelCaseToUnderscoresNamingStrategy 를 상속받아 uppercase로 변경

yml 에선언

spring.jpa.hibernate:
  naming:
    physical-strategy
public class CustomColumnUppercaseStrategy extends CamelCaseToUnderscoresNamingStrategy {
    @Override
    protected Identifier getIdentifier(String name, final boolean quoted, final JdbcEnvironment jdbcEnvironment) {
        if (isCaseInsensitive(jdbcEnvironment)) {
            name = name.toUpperCase(Locale.ROOT);
        }
        return new Identifier(name, quoted);
    }
}

 

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))
                        )
                );
.stream().collect(Collectors.toMap(A::getKey, B::getKey)
>> .stream().collect(Collectors.toMap(A::getKey, B::getKey, (k1,k2) -> k1)

java8 stream collect  toMap 사용 중 duplicate key 발생 시

Map 반환에 키 중복이 있을때 발생하는데,  오버로딩된 toMap 메소드 중 merge 기능이 있는걸 사용하면 된다. 

<실행되는 Collectors.class >

public static <T, K, U>
Collector<T, ?, Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper,
                                Function<? super T, ? extends U> valueMapper,
                                BinaryOperator<U> mergeFunction) {
    return toMap(keyMapper, valueMapper, mergeFunction, HashMap::new);
}

+ Recent posts