I solved my problem. I changed my mapping according to below and then directly delete the child.
But any comment on the solution. I think Hibernate has no effect on the solution and i solved it by hand. Because on any one-to-many you will do like this.
And any comment on what is the role of
all-delete-orphan.
Code:
<class name="Worksheet" table="WORKSHEET">
<property ...>
<property ...>
<bag name="tabsheets" [color=red]inverse[/color]="true" [color=red]cascade[/color]="all">
<key column="WORKSHEET_ID"/>
<one-to-many class="Tabsheet"/>
</bag>
</class>
<class name="Tabsheet" table="TABSHEET">
<property ...>
<property ...>
</class>
I forgot something in my first post :
The generated SQL (show_sql=true):
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: update TABSHEET set WORKSHEET_ID=null where WORKSHEET_ID=?
Hibernate: update TABSHEET set WORKSHEET_ID=? where TABSHEET_ID=?
Hibernate: update TABSHEET set WORKSHEET_ID=? where TABSHEET_ID=?
Hibernate: update TABSHEET set WORKSHEET_ID=? where TABSHEET_ID=?
and now it's like this:
The generated SQL (show_sql=true):
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: update TABSHEET set P1=?, P2=?, P3=? where TABSHEET_ID=?
Hibernate: delete from TABSHEET where TABSHEET_ID=?