Kamil Makaryk
Kamil Makaryk

Reputation: 1

ORA-00060: deadlock detected while waiting for resource - SpringData Jpa

I've got deadlock in my SpringDataJpa - "ORA-00060: deadlock detected while waiting for resource". The problem appears when then are a large number of queries. Is sth wrong with given piece of code?

***Maximum number of cars to delete never exceed 10

****I can't use batch delete or raw delete query, becauase I use envers and entites that would be deleted must be loaded into the application context

@Transactional
public Result replaceCarWithGivenBrand(Request request) {

    List<Car> cars = repository.findCarsByBrand(request.getBrand());
    
    deleteOldCars(cars);
    mapAndSaveNewCar(request);
    return Result.UPDATED;
}

private void deleteOldCars(List<Car> cars) {
    repository.deleteAll(cars);
    entityManager.flush();
}

private void mapAndSaveNewCar(Request request) {
    List<Car> cars = new ArrayList<>();
    repository.saveAll(cars);
}

I'd like avoid problem with deadlocks.

Upvotes: 0

Views: 65

Answers (1)

Sagar Rout
Sagar Rout

Reputation: 694

It would be difficult to comment without seeing the domain objects for both Car and Brands. But I don't understand why you have to explicitly the flush on deletion of cars. During transaction close, Hibernate will issue flush and commit.

Upvotes: 0

Related Questions