Hibernate version:
Hibernate 3.0
Name and version of the database:
Microsoft SQL Server 2005
Mapping documents:
Capability.hbm.xml:
Code:
<hibernate-mapping package="emst.dao.entities.capabilities">
<class name="Capability" table="CAP_Capability">
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<many-to-one name="currentAction" class="emst.dao.entities.capabilities.actions.Action" cascade="all" lazy="false"/>
</class>
</hibernate-mapping>
Action.hbm.xml:
Code:
<hibernate-mapping package="emst.dao.entities.capabilities.actions">
<class name="Action" table="CAP_Action">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="timeForCompletion" type="integer"/>
</class>
</hibernate-mapping>
Code:Code:
public class Capability {
private Long id;
private Action currentAction;
public Capability(){
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Action getCurrentAction() {
return currentAction;
}
public void setCurrentAction(Action currentAction) {
this.currentAction = currentAction;
}
}
Problem:The relationship between Capability and Action is a variation of the parent-child relationship. Throughout the lifespan a Capability will assign new Action objects to currentAction via:
Code:
this.setCurrentAction( SOME NEW ACTION)
When this happens I'd like Hibernate to delete the previously stored Action. As of now every Action object remains in the database even after all of the Capability objects have been removed.
If I were to make currentAction a list or map then it gives the behavior I want but currentAction will only have a single value. Anybody know how to get this behavior without needlessly making currentAction a collection?