Here is my data structure.
@Entity
public class JobEntity {
@Id
private Long id;
private String name;
@OneToMany(fetch = FetchType.EAGER,cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, mappedBy = "parentJob")
private List<JobEntity> subJobs;
@ManyToOne
@JoinColumn(name = "parent_job")
private JobEntity parentJob;
}
So the job entity has a tree data structure, If I want to add pessimistic lock like below, using JPA:
Map<String, Object> properties = new HashMap<>();
map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED);
entityManager.find(JobEntity.class, 1L,LockModeType.PESSIMISTIC_WRITE, properties);
Would the pessimistic lock work on all referenced sub rows in the tree data structure? Or just the row with id "1L"? Or just the rows directly referenced from "1L"?