인프런 커뮤니티 질문&답변
[hibernate 6] custom 함수 등록 방법 공유
작성
·
3.3K
·
수정됨
20
Hibernate 6에서는 강의에서 처럼 Dialect를 통한 함수 등록이 불가능합니다.
https://start.spring.io/로 Spring Boot 3버전으로 만드신 분들은 문제를 겪으실 거라고 생각합니다.
등록법
- FunctionContributer의 구현체를 만들어 준다.
package custom;
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.FunctionContributor;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.type.StandardBasicTypes;
public class CustomFunctionContributor implements FunctionContributor {
    @Override
    public void contributeFunctions(FunctionContributions functionContributions) {
        functionContributions.getFunctionRegistry()
            .register("group_concat", new StandardSQLFunction("group_concat", StandardBasicTypes.STRING));
    }
}
- src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor파일을 생성한다.
- 해당 파일에 직접 구현한 CustomFunctionContributor를 등록한다. - 패키지명.컨트리뷰터이름 형태로 등록!! 
- custom.CustomFunctionContributor
 


이렇게 하시면, 강의에서처럼 group_concat함수를 사용하실 수 있습니다.
Dialect는 변경 안하셔도 됩니다.







