1

I overrided all ImprovedNamingStrategy methods and placed for them breakpoints, but methods were not called in debug mode.

I have only one hibernate factory, so mistake because of other instance is impossible.

I think, the problem is in the key "hibernate.ejb.naming_strategy" or no?

    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
    <bean id="sqlSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.${jdbc.dialect}</prop>
                <prop key="hibernate.globally_quoted_identifiers=true">true</prop>
                <prop key="hibernate.enable_lazy_load_no_trans">false</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.show_sql">{hibernate.show_sql}</prop>
                <prop key="hibernate.ejb.naming_strategy">
                com.stub.utilities.dao.sql.hibernate.LowerCaseNamingStrategy
                </prop>
            </props>
        </property>
        <property name="annotatedClasses"/>
    </bean>
</beans>

Pom

<spring.version>4.2.4.RELEASE</spring.version>
<hibernate.core.version>5.0.7.Final</hibernate.core.version>
Arthur
  • 1,156
  • 3
  • 20
  • 49

1 Answers1

4

Hibernate 5 doesn't have any ImprovedNamingStrategy. It uses ImplicitNamingStrategy and PhysicalNamingStrategy interfaces. Strictly speaking, there is the class ImprovedNamingStrategy, for an example, in the Hibernate 5.1. But you can't use it to configure the SessionFactory.

An example to set ImplicitNamingStrategy

  <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="implicitNamingStrategy">
      <bean class="com.github.fluent.hibernate.cfg.strategy.hibernate5.Hibernate5NamingStrategy">
        <property name="tablePrefix" value="spring_" />
      </bean>
    </property>
  </bean>

You can use hibernate.implicit_naming_strategy and hibernate.physical_naming_strategy properties as well

<bean id="sqlSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.implicit_naming_strategy">
                  com.stub.utilities.dao.sql.hibernate.ImplicitNamingStrategy
                </prop>
                <prop key="hibernate.physical_naming_strategy">
                  com.stub.utilities.dao.sql.hibernate.PhysicalNamingStrategy
                </prop>
            </props>
        </property>
        <property name="annotatedClasses"/>
    </bean>
</beans>

You can refer my other answer about how to implement LowerCaseNamingStrategy

Implementing a NamingStrategy in Hibernate 5 (make autogenerated column names UPPERCASE)

Community
  • 1
  • 1
v.ladynev
  • 19,275
  • 8
  • 46
  • 67