I want to lock a table at the entity level in Hibernate/Spring Data JPA.
This is a mock-up of my code:
@Entity
@Data
@Table(name = "Armor")
public class Armor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OptimisticLocking
private String armorBrand;
}
Can I do this but for the entire table?
I'm currently using JpaRepository for my updates. I would like to keep using it instead of EntityManager.
CodePudding user response:
Use the following:
setLockMode(String alias, LockMode lockMode)
CodePudding user response:
Maybe @Lock
is what you are looking for.
@Lock(LockModeType.PESSIMISTIC_READ)
public Optional<Armor> findById(Long armorId);