I am using spring boot 1.2.3.RELEASE version with JPA over hibernate. I am experiencing following exception
org.springframework.dao.InvalidDataAccessApiUsageExce
Ok I found out a way of making it works.
Just put a @Transactional
annotation (org.springframework.transaction.annotation.Transactional) in your deleteOrder method at OrderService.
@Transactional
public void deleteOrder(long customerId){
repo.deleteByCustomerId(customerId);
}
I really don't know why the second works. I guessing that since it is an direct method from the CrudRepository interface someway it knows how to execute it atomically.
The former one is a call to the deleteByCustomerId. This call will be processed to find out the customer with the specified id and then deletes it. For some reason it makes the use of an explicit transaction.
Again it is just a guess. I'll try to contact some spring developers and maybe open a issue to verify this behaviour.
Hope it helps!
Reference: http://spring.io/guides/gs/managing-transactions/