在我的服务中,当我想通过方法从数据库中获取对象时:
public ParkingEntity findParking(String idParking) {
return parkingRepository.findById(idParking).orElseThrow((() ->
new ParkingNotFoundException(idParking)));
}
存储库中的“findById”:
public interface ParkingRepository extends JpaRepository<ParkingEntity, String> {
@Lock(LockModeType.PESSIMISTIC_FORCE_INCREMENT)
Optional<ParkingEntity> findById(String s);
}
我正在
org.hibernate.exception.GenericJDBCException: could not extract ResultSet
和
Caused by: java.sql.SQLException: Cannot execute statement in a READ ONLY transaction.
只有当我添加
@Lock(LockModeType.PESSIMISTIC_FORCE_INCREMENT)
.无@锁定,无任何错误。我的parkingEntity车身:
@Entity
@Table(name = "parking")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ParkingEntity {
@Id
@Column(name = "parking_id")
private String idParking;
private String name;
private String address;
private int numberOfParkingSlots;
private int numberOfChargers;
private boolean isLPGAllowed;
private Double widthOfSlot;
@OneToMany(mappedBy = "parking", cascade = CascadeType.ALL)
private Set<CarEntity> cars = new HashSet<>();
@Version
private Long version;