私のシナリオでは、アルバムと画像の 2 つのテーブルがあります (関係は 1 対多です)。
単純化されたマッピングは次のとおりです。
<hibernate-mapping>
<class name="Album" table="album">
<id name="id" column="album_id" type="int">
<generator class="sequence">
<param name="sequence">TestObject_seq</param>
</generator>
</id>
<set name="image" table="image" order-by="orderBy">
<key column="album_id" />
<composite-element class="Image">
<property name="caption" column="caption" type="string"/>
<property name="path" column="path" type="string"/>
<property name="orderBy" column="orderBy" type="int"/>
</composite-element>
</set>
</class>
</hibernate-mapping>
私はこれをやっています:1.データベースでオブジェクトを見つけ、2.コレクションからいくつかのレコードを削除し、3.saveOrUpdateを呼び出します。
Album album = dao.getAlbum("Name of album");
Set<Image> imagesToRemove = getImagesToRemove();
album.getImages().removeAll(imagesToRemove);
dao.saveOrUpdate(album);
dao.flushAndClear();
テーブル イメージの一部の値が null になるまでは、すべて問題ありません。たとえば、キャプションには null 値があります。
ログで私は見ることができます:
DEBUG SQL:292 - delete from image where album_id=? and caption=? and path=? and orderBy=?
DEBUG AbstractBatcher:343 - preparing statement
DEBUG IntegerType:59 - binding '463' to parameter: 1
DEBUG StringType:52 - binding null to parameter: 2
...
この場合、delete ステートメントはレコードを削除しません。
私が間違っていることは何ですか?