• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

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

23.12.09 13:35 작성 23.12.09 13:58 수정 조회수 848

6

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

답변 2

·

답변을 작성해보세요.

0

김민희님의 프로필

김민희

2024.02.05

감사합니다!

 

0

codesweaver님의 프로필

codesweaver

2023.12.09

안녕하세요. codingNoob12님

정보 공유 감사합니다 :)