dime wrote:
That probably means that the object you are trying to delete is a child of some other collection. Setting up cascade="all" for the object means that its children would be deleted/updated automatically unless they don't belong to some other parent.
you have to remove the object you are trying to delete for its parent collection.
I'm having the same problem and I am removing the child object from the parent collection.
The code --
Code:
for (Iterator ip = team.getPlayers(). iterator(); ip.hasNext();) {
Player player = (Player) ip.next();
if (player.getName().equals("Open")) {
Transaction tx = hibSession.beginTransaction();
ip.remove();
hibSession.save(team);
hibSession.delete(player);
tx.commit();
continue;
}
}
The tx.commit() throws the exception. Team is mapped as follows --
Code:
<hibernate-mapping package="">
<class name="com.widget.Team" table="teams">
<id name="id" column="id" type="java.lang.Integer">
<generator class="identity"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<set name="players" cascade="all-delete-orphan" >
<key column="teamid" />
<one-to-many class="com.widget.Player" />
</set>
</class>
</hibernate-mapping>
After the exception is thrown, the row in the player table has teamid set to null. However, my expectation is that it would have been deleted since it's now orphaned.
Any help here? Thanks!![/code]