Hibernate naming strategy changing table names

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

it worked for me. here are the versions i'm using:

Spring Boot (v1.4.2.RELEASE)
Hibernate Core {5.0.11.Final}

The problem lies in spring-boot-1.4 - it seems like they have changed the properties (or whatever) I've now found this answer ImprovedNamingStrategy no longer working in Hibernate 5, but it still didn't resolve correctly. So I have changed the code a little to not use the underscore method and to extend the newly introduced class SpringPhysicalNamingStrategy:

package com.foo;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

import java.io.Serializable;
import java.util.Locale;


public class RealNamingStrategyImpl extends org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy implements Serializable {

    public static final PhysicalNamingStrategyImpl INSTANCE = new PhysicalNamingStrategyImpl();

    @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());
    }

}

And in application.properties I've changed the deprecated line to

spring.jpa.properties.hibernate.physical_naming_strategy=<package>.RealNamingStrategyImpl

Now it uses exactly the table and column names as I have them in my entity files.


For one who wants to upper case in Postgresql and Spring boot 1.5.2

public class CustomDatabaseIdentifierNamingStrategy extends org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy implements Serializable {

    public static final long serialVersionUID = 1L;
    public static final CustomDatabaseIdentifierNamingStrategy INSTANCE = new CustomDatabaseIdentifierNamingStrategy();

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

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

}