I have an object called Classroom:
@Entity
public class Classroom {
@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
@JoinColumn(name = "girl", referencedColumnName = "id", nullable = true)
private GirlsInformationObject girl;
@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
@JoinColumn(name = "boy", referencedColumnName = "id", nullable = true)
private BoysInformationObject boy;
}
Now, imagine I have two threads, which both keep information about the Classroom and update the object where necessary. One of the threads is updating the object with information about the girls, and the other is updating the object with information about the boys.
Imagine both threads accessing the same Classroom entry at the same time. The threads adjust the appropiate InformationObject and store the object in the database, using ClassroomRepository.save(classRoom)
. Can I prevent the OptimisticLockException if the InformationObjects would be lazily loaded?