When an update is performed on a lazy one-to-one association with optimistic locking set to OptimisticLockType.DIRTY previous state of that association is not loaded, leading to missing parameters required to perform an update statement. With a model like:
@Entity(name = "Person")
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
public static class Person {
@Id
Long id;
@Column
String name;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
Address address;
}
@Entity(name = "Address")
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
public static class Address {
@Id
Long id;
@Column
String street;
}
Then an operation that leads to an error:
Person person = entityManager.find( Person.class, 1L );
person.getAddress().setStreet( "new Street" );
Results in:
Will submit a reproducer. |