Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Hibernate to make table/column name with uppercase AND lowercase letters

I have to use table and column names in my Postgres that contain uppercase and lowercase letters. For example OrgInfo

I would like to create such tables and columns using Hibernate. If I use standard approach:

@Entity 
@Table(name = "OrgInfo")

then I receive the table with the name "org_info".

How I can configure Hibernate to create tables and columns with exact given names including uppercase and lowercase letters?

I have tried to use

@Entity 
@Table(name = "\"OrgInfo\"")

with no effect.

Also I use Spring Boot and have tried to configure like this:

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.DefaultNamingStrategy OR spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

like image 642
Kirill Ch Avatar asked Sep 12 '25 02:09

Kirill Ch


2 Answers

Try to configure Hibernate "physical-strategy" in your configuration file as follows:

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

like image 58
SachinSarawgi Avatar answered Sep 14 '25 15:09

SachinSarawgi


The working solution is to use both parts:

@Entity
@Table(name = "\"OrgInfo\"")

and

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

like image 38
Kirill Ch Avatar answered Sep 14 '25 17:09

Kirill Ch