I cannot delete a child from the database. From the method, org.apache.struts.action.Action.execute()I remove the child from the parent List, and also call session.delete(child). I simplified the code below and included only what I consider to be relavent.
Hibernation display
<class
name="xxx.xxx.hibernate.Parent"
table="parent">
...
<list
name="children"
cascade="all,delete-orphan"
lazy="true"
inverse="true">
<key column="parent_id"/>
<index column="list_index"/>
<one-to-many class="xxx.xxx.hibernate.Child"/>
</list>
</class>
<class
name="xxx.xxx.hibernate.Child"
table="child">
...
<many-to-one
name="parent"
class="xxx.xxx.hibernate.Parent"
not-null="true"
column="parent_id" />
</class>
Excerpt from execute () method
Transaction tx = session.beginTransaction();
try {
Parent parent = (Parent) session.get(Parent.class, getParentId());
Iterator i = form.getDeleteItems().iterator();
while(i.hasNext()){
Child child = (Child) i.next();
session.delete(child);
parent.getChildren().remove(child);
}
session.saveOrUpdate(parent);
tx.commit();
} ...
session.delete(child);, parent.getChildren().remove(child); , . - . , ( System.out.println(); , ), . , - , , , !
Hibernate this SO . .
? ! .
:
- Java 1.4.2
- SQL Server 2005
- Hibernate 3.0.5
- Struts 1.2.7
- Apache Tomcat 5.0.28