Hibernate Table Field Naming Strategies / Conventions With Spring boot.

Jahid Momin
3 min readApr 12, 2022

Let’s assume that we are creating a maven spring boot application with spring data JPA.

Made with Canva

The Spring Data JPA dependency brings in the Hibernate dependencies for us.

Adding Spring boot Data JPA starter in POM

Also, we need database, so we are using MySQL here, so we add MySQL connector dependency / you can use any db that's not a problem.

Now we will create some Entities/Model to create respective table in database.

Suppose we have a class name Person

Person POJO class // assume with getter/setter

Set database url , username and password with some hibernate properties in application.properties.

MySQL Credentials.

Adding some SQL debugging in our properties file

first one is showing generated SQL and second one is to update tables data

and last one is to set dialect.

After running application, see console.

Hibernate generated Query

As we can see, the fields use snake case and are lowercased, following the Spring conventions.

Spring Boot Naming Strategies

Hibernate maps field names using a physical strategy and an implicit strategy.

  • spring.jpa.hibernate.naming.physical-strategy defaults to org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
  • spring.jpa.hibernate.naming.implicit-strategy defaults to org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

by default, they are working like this:

  • Replace dots with underscores
  • Change camel case to snake case, and
  • Lower-case table names

example, an FirstName entity would be created as the first_name table.

So I want to change this default strategies to JPA 1.0 way. How can I do ?

We have a simple way, just add properties in application.properties file 😁.

Strategies of JPA 1.0’s naming convention

Now drop previous db and run again application , at this time you’ll see different DDL queries.

JPA 1.0’s naming convention

Wait, wait … if we wanted to use the JPA 2.0 naming rules, we’d need to set ImplicitNamingStrategyJpaCompliantImpl as our implicit strategy.

I got a same result for JPA 2.0. You will also try it out.😒

Thanks for reading.

Don't forget to share 😁👍.

--

--

Jahid Momin

Team Lead | Sr Software Engineer | Spring boot | Microservices | JavaScript | CodeIgniter | HTML | CSS | ReactJS | NextJS | Youtuber | Writer