0

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"?

Man Shen
  • 401
  • 2
  • 16

1 Answers1

0

It should work but note that if you are using Hibernate, unfortunately it's not yet supported

The javax.persistence.lock.scope is not yet supported as specified by the JPA standard.

From Hibernate Docs

Related Ticket

Enoobong
  • 1,594
  • 2
  • 15
  • 25