네이밍 문법에는 카멜 케이스(CamelCase), 스네이크 케이스(snake_case)가 존재합니다.
Hibernate에서 기본으로 지원하는 Default 옵션은 lower_snake_case 이며,
테이블 및 컬럼 네이밍 규칙에 적용됩니다.
대학생 엔티티가 있다고 가정해 봅니다.
@Entity
public class CollegeStudent{
@Id
@Column(name = "studentId")
private Long id;
private String name;
private String collegeNo;
}
ddl-auto 옵션 사용 시 아래의 DDL 문장을 생성하여 DB에 반영합니다.
단 h2(로컬 DB)에서는테이블 및 컬럼 명칭을 대문자(Upper)로 생성합니다.
create table college_student (
student_id bigint(20) not null,,
name varchar(255),
college_no varchar(255)
)
팀에서 정한 네이밍 규칙이 lower_snake_case가 아니라면 옵션 변경이 필요합니다.
저희 팀에서는 CamelCase를 사용하고 있어 물리적 명칭 전략을 적용하였습니다.
1. 암시적 전략
: 명시적으로 테이블, 컬럼명을 지정하지 않으면 논리적으로 자동 생성 (Default Option)
spring.jpa.hibernate.naming.implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
The ImplicitNamingStrategy would only be applied if an explicit name was not given.
[출처 : Hibernate ORM Final User Guide]
2. 물리적 명칭 전략
: 클래스, 변수 이름 기준으로 테이블, 컬럼명 생성
spring.jpa.hibernate.naming.physical-strategy:
org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
The PhysicalNamingStrategy will be applied regardless of whether the attribute explicitly specified the column name or whether we determined that implicitly. The ImplicitNamingStrategy would only be applied if an explicit name was not given. So, it all depends on needs and intent.
[출처 : Hibernate ORM Final User Guide]
읽어주셔서 감사합니다.
레퍼런스
https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html
반응형
최근댓글