0

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?

Joetjah
  • 6,292
  • 8
  • 55
  • 90

1 Answers1

0

actually, concurrent issue ocurring here resulting an optimisticException. dont you do this update in separate session? Like in one transaction or session you update the girls in that object and in second transaction or session you fetch the row and update the field of boys. Please consider this

Subrata nath
  • 172
  • 10
  • The question was if I could evade all that work by simply setting the type to `FetchType.EAGER`, since it's not that object that gets updated. – Joetjah Apr 12 '17 at 18:36