私は2つのクラス、ProductConfigurationとSubProductを持っています。 リストからの休止と削除
私はこの方法で行う設定のサブプロダクト、交換したい
:productConfiguration.getSubProducts().clear();
productConfiguration.getSubProducts().addAll(newSubProducts);
をこれを行うには、Hibernateは親(製品構成)nullにのIDを設定しようとし、データベース内の行を更新します。これは、親IDが外部キーであるため、失敗します。したがって、NULL可能ではありません。
ProductConfigurationからサブプロダクトへのマッピング:
<bag name="subProducts"
table="sub_product"
cascade="all-delete-orphan"
access="field"
lazy="false">
<key column="parent_id"/>
<one-to-many class="com.conscius.cpt.core.product.SubProduct"/>
</bag>
<many-to-one name="parentProduct"
class="com.conscius.cpt.core.product.ProductConfiguration"
column="parent_id"
access="field"
not-null="true"
cascade="none"/>
親が削除されたときにサブ製品がデータベースに存在することはありますか?そうでなければ、これを見てください:http://docs.jboss.org/hibernate/core/3.3/reference/en/html/example-parentchild.html#example-parentchild-bidir – zmf
私はどこが間違っているかを見ます。私は、ProductConfiguration側でinverseステートメントが欠落していました。私はその答えをできるだけ早く追加します。 – SimonPip