I have two entities "Device" and "DeviceStatus" that are mapped by a unidirectional, mandatory One-to-One relationship with CascadeType ALL. That way I can easily create and delete devices and the deviceStaus gets created and deleted accordingly. A deviceStatus cannot exist without a device.
The mapping looks like this:
Code:
public class Device {
private Long id;
private DeviceStatus status;
@OneToOne(optional = false)
@Cascade(value = { CascadeType.ALL })
public DeviceStatus getStatus() {
}
public void setStatus(DeviceStatus status) {
this.status = status;
}
//getter + setter for id
}
public class DeviceStatus {
private Long id;
private String statusText;
//getter + setter
}
The problem is that the deviceStatus is updated by some background process very often. If I want to update a device by the GUI I almost always get a ConcurrentModificationException because the deviceStatus was updated between loading the device into the client and updating it back in the server.
Question is: why is Hibernate trying to update the deviceStatus as the GUI has only changed the device? I thought Hibernate would check which objects are really changed?