Вопрос

using this in my hibernate cfg:

<property name="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</property>
<property name="hibernate.hbm2ddl.auto">create</property>

This should make all my tables and column snake_case in database.

But it is just making them camelCase.

What could be the problem?

private String myName;

in my database it is still myName(varchar(255))

Это было полезно?

Решение

Setting hibernate.ejb.naming_strategy programmatically worked.

configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-programmatic

Still wondering why it didn't work from XML, should work.

Другие советы

@Jaanus was too hasty in rejecting the links provided by @Renjith

The link states that it does work in XML but has to be injected as a property of the session factory as shown in the XML code extract below:


    <!-- object to relational mapping configuration -->
  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="hibernateProperties">
        <property name="map">
          <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

            <entry key="hibernate.hbm2ddl.auto" value="validate" />

            <entry key="hibernate.connection.charSet" value="UTF-8" />

            <entry key="hibernate.show_sql" value="true" />
            <entry key="hibernate.jdbc.batch_size" value="0" />
          </map>
        </property>
    </property>
    <property name="namingStrategy">
      <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
    </property>
    <property name="dataSource" ref="dataSource" />
    ...
  </bean>

hope below mentioned links shed some thoughts.

link 1 and link 2

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top