I just want to get to know. I declared a attribute name named userId. But it appears in MySQL workbench as user_id. Is this normal?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name= "userId")
private Long userId;
CodePudding user response:
Spring Boot configures SpringPhysicalNamingStrategy
by default. If you are using hibernate / JPA, all dots are replaced by underscores and camel cases are replaced by underscores as well. By default, all table names are generated in lower case but it is possible to override that flag if your schema requires it.
In order to override it, We only need to indicate it in our properties file
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
Or, expose them as @Beans
:
@Bean
public PhysicalNamingStrategy physical() {
return new PhysicalNamingStrategyStandardImpl();
}
@Bean
public ImplicitNamingStrategy implicit() {
return new ImplicitNamingStrategyLegacyJpaImpl();
}