0

I have 2 classes Tema(Homework) and Disciplina (course), where a Course has a Set of homeworks. In Hibernate i have mapped this to a one-to-many associations like this:

<class name="model.Disciplina" table="devgar_scoala.discipline" >
<id name="id"  >
    <generator class="increment"/>
</id> 
<set name="listaTeme" table="devgar_scoala.teme">
    <key column="Discipline_id" not-null="true" ></key>
    <one-to-many class="model.Tema" ></one-to-many>
</set>
</class>

<class name="model.Tema" table="devgar_scoala.teme" >
<id name="id">
    <generator class="increment" />
</id>
<property name="titlu" type="string" />
<property name="cerinta" type="binary">
    <column name="cerinta" sql-type="blob" />
</property>
</class>

The problem is that it will add (insert rows in the table 'Teme') but it won't delete any rows and i get no exceptions thrown.

Im using the merge() method.

4

2 に答える 2

0

あなたの質問は不明ですが (どのように保存して削除しますか?)、設定する必要があることをお勧めしますcascade:

<set cascade="all-delete-orphan">

補足として、母国語の名前は避けてください。

于 2010-04-11T13:38:48.763 に答える
0

あなたの説明によると、 aTemaはその なしでは存在できないことを理解していDisciplinaます。コレクションから a を削除するTemaと、それを削除したいということです。Hibernate にこれを行うように指示するには、 を使用する必要がありますcascade="all-delete-orphan"

<set name="listaTeme" table="devgar_scoala.teme" cascade="all-delete-orphan">
    <key column="Discipline_id" not-null="true" ></key>
    <one-to-many class="model.Tema" ></one-to-many>
</set>

オンライン ドキュメントを参照してください。

于 2010-04-11T14:02:16.513 に答える