1

I am implementing an application in spring-boot with the database Postgres, I want customized column name i.e in camelcase

@Column(name = "customerId")
private Integer customerId;

@Column(name = "accountNumber")
private Integer accountNumber;

for that, I have added all properties

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.DefaultNamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl`

which I got from spring docs and StackOverflow but none of is working in my case, every time column names created with these names: accountnumber customerid

I am trying to override with these codes:

public class RealNamingStrategyImpl extends SpringPhysicalNamingStrategy
    implements Serializable {

public static final PhysicalNamingStrategyStandardImpl INSTANCE = new PhysicalNamingStrategyStandardImpl();

@Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
    return new Identifier(name.getText(), name.isQuoted());
}

@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
    return new Identifier(name.getText(), name.isQuoted());
}

}

But didn't get the expected result. can anyone help me with that? Thank you!

Khushi
  • 103
  • 9
  • Please share your properties file. – Ponni May 18 '20 at 09:43
  • Does postgresql even support uppercase column names? If I understand this correctly - they are converted to lower case per default, if you don't quote them. https://stackoverflow.com/questions/20878932/are-postgresql-column-names-case-sensitive – TomStroemer May 18 '20 at 09:46
  • I have shared my properties above as well: – Khushi May 18 '20 at 09:49
  • @TomStroemer but I need my column names the way I have specified, and yes by manually getting into DB and using Alter I am able to do but I want JPA should auto-create the way I defined. – Khushi May 18 '20 at 09:52
  • [This](https://stackoverflow.com/a/58849104/7598851) answer provides information on how to customize column names. – MartinBG May 18 '20 at 20:53
  • 1
    Thank you for responding, I got my answer, as I have mentioned that I was using Postgres using spring boot and there are some special rules to put a capital in a table or in column names: we need to use quotation. example :@Column(name = "\"customerId\"") – Khushi May 19 '20 at 08:02

0 Answers0