Hibernate升级 - 更改了默认的约束命名策略

时间:2016-07-27 15:38:01

标签: hibernate foreign-keys constraints upgrade

将Hibernate版本从4.1.12.Final升级到5.1.0.Final后,我们意识到Hibernate自动生成的外键约束的命名约定已经改变。

Hibernate4生成的外键约束:     “fk9ad71e905f9bc6ca”     “fk9ad71e90ab88f852”

Hibernate5生成的外键约束:     “fkcaaxqultt51c7wraf5f4mq3xb”     “fkggqbdp3uqmi0grv8kwcs5wc8a”

如果有一种方法可以明确指定命名约定,那么我们就不会丢弃并重新创建约束(在生产中,由于大型数据集,它将花费数小时)。

Hibernate许多实体示例:

@ManyToMany(cascade=CascadeType.MERGE)
@JoinTable(name = "GEO_ZONE_ZIP", joinColumns = @JoinColumn(name = "GEO_ZONE_GEO_ZONE_ID"), inverseJoinColumns = @JoinColumn(name = "ZIPSTATESET_ZIP_STATE_ID"))
public Set<ZipState> getZipStateSet() {
    return this.zipStateSet;
}

休眠配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

        <property name="dataSource" ref="${hibernate.datasource}"/>

        <property name="hibernateProperties">
            <props>

                <!--
                <prop key="hibernate.connection.driver_class">${hibernate.jdbcdriver}</prop>
                <prop key="hibernate.connection.url">${hibernate.connection.url}</prop>
                <prop key="hibernate.connection.username">${hibernate.connection.username}</prop>
                <prop key="hibernate.connection.password">${hibernate.connection.password}</prop>
                 -->

                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql"> ${hibernate.showsql}</prop>
                <prop key="hibernate.format_sql">${hibernate.formatsql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.sqlcomments}</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>

                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <prop key="hibernate.cache.use_query_cache">false</prop>
                <prop key="hibernate.generate_statistics">true</prop>
            </props>
        </property>

非常感谢任何帮助,

罗马。

0 个答案:

没有答案