[서버][스프링] Entity 어노테이션으로 만들어지는 table 이름 조절

프로그래밍/서버2021. 3. 20. 12:59

스프링에서 Entity 어노테이션을 사용하면 (설정에 따라 다르겠지만) table이 생성됩니다.

그런데 기본적으로 @Table(name="userInfo") 와 같이 테이블 이름을 설정했더라도 실제 db에 생성되는 table 이름은 user_info와 같이 언더스코어(밑줄)로 변형되어 생성됩니다.

 

이는 org.springframework.boot.orm.jpa.SpringNamingStrategy 에 따른 것입니다.

 

application.properties에

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

를 설정하면 이름이 변경되지 않고 그대로 생성됩니다.

 

 

참고

stackoverflow.com/questions/29087626/entity-class-name-is-transformed-into-sql-table-name-with-underscores

 

Entity Class name is transformed into SQL table name with underscores

I have the following entity defined: @Entity @Table(name = "EmailTemplate") public class EmailTemplate { Despite the table annotation, I receive java.sql.SQLException: Invalid object name '

stackoverflow.com

docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#spring.jpa.hibernate.naming.physical-strategy

 

Common Application properties

Various properties can be specified inside your application.properties file, inside your application.yml file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume

docs.spring.io

www.baeldung.com/hibernate-field-naming-spring-boot

 

Hibernate Field Naming with Spring Boot | Baeldung

Learn how Spring Boot configures Hibernate's field naming strategies and how to configure them yourself.

www.baeldung.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역