인프런 커뮤니티 질문&답변

codingNoob12님의 프로필 이미지

작성한 질문수

자바 ORM 표준 JPA 프로그래밍 - 기본편

JPQL 함수

[hibernate 6] custom 함수 등록 방법 공유

23.12.09 13:35 작성

·

2K

·

수정됨

11

Hibernate 6에서는 강의에서 처럼 Dialect를 통한 함수 등록이 불가능합니다.

https://start.spring.io/로 Spring Boot 3버전으로 만드신 분들은 문제를 겪으실 거라고 생각합니다.

 

등록법

  1. 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));
    }
}

 

  1. src/main/resources/META-INF/services/org.hibernate.boot.model.FunctionContributor파일을 생성한다.

  2. 해당 파일에 직접 구현한 CustomFunctionContributor를 등록한다.

     

    1. 패키지명.컨트리뷰터이름 형태로 등록!!

    2. custom.CustomFunctionContributor

이렇게 하시면, 강의에서처럼 group_concat함수를 사용하실 수 있습니다.

 

Dialect는 변경 안하셔도 됩니다.

 

reference

https://aregall.tech/hibernate-6-custom-functions

답변 3

0

i_12244104님의 프로필 이미지

2024. 08. 05. 18:40

감사합니다 :D

0

김민희님의 프로필 이미지

2024. 02. 05. 18:12

감사합니다!

 

0

codesweaver님의 프로필 이미지

2023. 12. 09. 19:44

안녕하세요. codingNoob12님

정보 공유 감사합니다 :)