Hello,
I just observed that cascade="all" do not delete child object when we set it to null. For example there are two classes:
public class User {
private int id;
private Address address;
...
}
public class Address {
private int id;
private String street;
}
when we insert Address object into address field in User object, and next save it everything is alright. When we in next step set address field to NULL, and saveOrUpdate(user) the address object isn't deleted from address table.
Mappings:
<class name="xxx.entities.user.User" table="User">
<id name="id" type="integer" unsaved-value="0">
<generator class="native" />
</id>
<one-to-one name="address" cascade="all" lazy="false" />
</class>
<class name="xxx.entities.user.Address">
<id name="id" type="integer" unsaved-value="0">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<one-to-one name="user" constrained="true" />
</class>
So is there a bug in implementation of this? How could I repair it in code?
Best regards,
Adr
|