Im testing with some sample code, the entities are Car and Wheels. Where a car has a one-to-many relationship to wheel.
some code snippets:
the relation declaration
Code:
@OneToMany(cascade=CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Collection<Wheel> getWheels() {
return wheels;
}
my junit test method
Code:
public void testCascade() {
Car car = new Car();
Wheel wheel = new Wheel();
car.addWheel(wheel);
DAO.makePersistent(car);
long id = car.getObjectId();
newTransaction();
car = new Car();
car.setObjectId(id);
car.setVersion(0);
DAO.update(car);
newTransaction(); //commits the transaction, here the exception is thrown
}