【发布时间】:2012-11-23 21:46:51
【问题描述】:
我有非常简单的架构 - 一对多关系中的两个表:
<hibernate-mapping package="my.app">
<class name="CorrelationKey" table="CORRELATION_KEYS">
<id name="id" column="CORRELATION_ID">
<generator class="native"/>
</id>
<set name="correlationKeyParts" cascade="all-delete-orphan" lazy="false">
<key column="CORRELATION_ID"/>
<one-to-many class="CorrelationKeyPart"/>
</set>
...
</class>
</hibernate-mapping>
CorrelationKey 类型的对象的保存和更新工作正常,并且更改传播到集合。但是当我尝试删除 CorrelationKey 对象时,我收到以下错误:
108090 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: update or
delete on table "correlation_keys" violates foreign key constraint "fk23630e23e9b29c52"
on table "correlation_key_parts"
Detail: Key (correlation_id)=(162) is still referenced from table "correlation _key_parts".
我在 Windows 机器上使用 PostgreSQL 9.1。
非常感谢。
【问题讨论】:
-
@JBNizet 我在尝试清空表
session.createQuery("delete from CorrelationKey").executeUpdate();时看到错误。感谢您查看此内容。
标签: hibernate postgresql hibernate-onetomany