在数据库中自动创建唯一约束

时间:2018-07-18 13:05:21

标签: postgresql hibernate constraints unique

我在Postgres数据库中发现,表上有一个唯一的约束,但尚未创建。

错误消息:

SqlExceptionHelper - FEHLER: doppelter Schlüsselwert verletzt Unique-Constraint »uconstr_service_out_mapping«
  Detail: Schlüssel »(service_id, mapping_id)=(7, 262144)« existiert bereits.

我的第一个想法是,Hibernate必须自动生成此约束。但是我们使用以下配置禁用了自动生成DDL:

<property name="hibernate.hbm2ddl.auto" value=""/>

我们正在使用Liquibase创建表:

<changeSet author="foo" id="bar">
        <createTable tableName="service_in_mapping">
            <column name="masterdata_type" type="INT4">
                <constraints nullable="false"/>
            </column>
            <column name="service_id" type="INT8">
                <constraints nullable="false"/>
            </column>
            <column name="service_type" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="non_matching" type="VARCHAR(20)"/>
            <column name="mapping_id" type="INT8"/>
        </createTable>
</changeSet>

如何不断创建这种独特的约束?有什么想法吗?

使用的依赖项版本:

  • 休眠5.2.8
  • Postgres Jdbc 9.1-901.jdbc4

0 个答案:

没有答案
相关问题