본문 바로가기

컴퓨터/Spring + JPA

Spring Boot 4.0 마이그레이션: Hibernate Naming Strategy 동작하지 않는 이슈

반응형

문제 상황

Spring Boot 3.x에서 4.0으로 마이그레이션 후, 테스트 실행 시 다음과 같은 에러가 발생했음.

ERROR: column u1_0.adultCertificatedAt does not exist

hibernate naming strategy 를 org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy, org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl 설정했는데도 camelCase가 snake_case로 안 바뀜.

원인, 해결

hibernate7 부터 naming strategy 에 따옴표 있는 경우 처리하는 로직이 변경된듯.
globally_quoted_identifiers 말고 auto_quote_keyword 사용하도록 변경

spring:
  jpa:
    hibernate:
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl
        implicit-strategy: org.springframework.boot.hibernate.SpringImplicitNamingStrategy
    properties:
      hibernate:
        # globally_quoted_identifiers: true  ← 이거 빼고
        auto_quote_keyword: true  # ← 이거 쓰기

ref: https://github.com/spring-projects/spring-data-jpa/issues/4091

반응형