I was wondering why an UPDATE is called when cascade-deleting a child record on a uni-directional one-to-many relationship. Why doesn't it call a DELETE? Does it UPDATE the parent ID to null then DELETE (I've never gotten far enough to tell :)? Is there a way of avoiding this?
I know that the DELETE will work if I change the relationship to bi-directional. But since everything else is working (and makes sense) as a one-to-many uni-directional relationship I'd hate to change it. Please tell me the answer is something simple :)
I have the following one-to-many mapping:
Code:
<hibernate-mapping>
<!-- Season -->
<class name="com.fgl.ina.mastertables.seasons.Season" table="season">
<id name="seasonID" column="season_ID" type="int">
<generator class="identity"/>
</id>
<property name="activeIndicator" column="active_indicator" type="boolean"/>
<map name="seasonDescriptions" lazy="false" cascade="all-delete-orphan" table="season_description">
<key column="season_ID"/>
<index column="locale" type="string"/>
<one-to-many class="com.fgl.ina.mastertables.seasons.SeasonDescription"/>
</map>
</class>
<!-- Season's Description -->
<class name="com.fgl.ina.mastertables.seasons.SeasonDescription" table="season_description" >
<composite-id unsaved-value="none">
<key-property name="ID" column="season_ID"/>
<key-property name="language" column="locale" type="string"/>
</composite-id>
<property name="description" column="description" type="string"/>
</class>
</hibernate-mapping>
Here is my code in a DispatchAction for delete:
Code:
public ActionForward delete (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
SeasonForm seasonForm = (SeasonForm)form;
Season season = new Season(seasonForm.getSeasonID());
try{
DataAccessService.delete(PersistanceFilter.getSession(), season);
}catch (Exception e){
errors.add("error", new ActionError("seasonform.error.delete"));
}
if(!errors.isEmpty()){
saveErrors(request, errors);
return (mapping.getInputForward());
}
return (mapping.findForward("success"));
}
The delete method is very simple:
Code:
public static void delete(Session session, Object obj) throws HibernateException {
session.delete(obj);
session.flush();
}
Clicking Delete in the JSP produces the following error message:
Code:
Hibernate: update season_description set season_ID=null, locale=null where season_ID=?
Severe: [SQLServer JDBC Driver]Cannot insert the value NULL into column 'locale', table 'INA.dbo.season.description'; column does not allow nulls. UPDATE fails.
My colleague wrote the following post but since no one answered and we are still experiencing the problem I am re-posting (about my own code).
http://forum.hibernate.org/viewtopic.php?t=924490
Thank you for any help.
Ursula