배경

현재 프로젝트에서 QueryDSL을 사용 중인데 여기에 집계함수를 사용하고 싶어서 사용자 함수 추가를 위해 서치 후 적용해보려고 했다. 그런데 이게 웬일.. Spring boot 3점대에서는 hibernate 6.1을 기본으로 사용하고 있어서 당장 올해 3월까지 올라온 블로그 글의 코드도 적용되지 않았다.. 그래서 한시간을 고생해서 적용해보고 고치고 하다가 김영한님 JPA 강의의 커뮤니티에 어떤 친절한 분이 해결방안을 올려주셨다.. 정말 천사,,

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0.0-M4-Release-Notes

해결

  1. FunctionContributor의 구현체를 만들어준다.
    public class CustomFunctionContributor implements FunctionContributor {
        
        @Override
        public void contributeFunctions(FunctionContributions functionContributions) {
            functionContributions.getFunctionRegistry()
                .register("group_concat", new StandardSQLFunction("group_concat", StandardBasicTypes.STRING));
        }
    }
    
  2. src/main/resources 하위에 META-INF/services/org.hibernate.boot.model.FunctionContributor 파일을 생성한다.
  3. 해당 파일에 1번의 구현체를 등록한다.

    • 패키지명.구현체 이름의 형태로 등록
    • com.example.com.config.~Contributor - yml 파일의 dialect 변경은 필요없음


시도

참고