Hello!!
I'm using Hibernate 3 with annotations and I use it with Spring's Hibernate Template.
Here are two classes I use:
public class Car{
...
}
public class Driver{
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="driver")
@Cascade(value=CascadeType.DELETE_ORPHAN)
@JoinColumn(name = "driver_id")
protected List<Car> cars;
}
Well, I've omitted some code, that doesn't have to do with my problem (as far as I can see).
When I remove some cars from a driver I've got no problems. But when I remove ALL OF THEM and the driver has no car, Hibernate doesn't delete them at all. They're there in the DB. If later I add one or more cars to this driver, the previously remove cars get deleted from the database.
It seems DELETE_ORPHAN it only works when I don't remove ALL the cars. It works well as long as I leave at least one. Did anybody know this issue? Am I doing anything wrong?
Thank you very much!
|