I use spring JPA and custom repository extends JpaRepository, for an very easy function:
@Transactional
void functionA(Book Book){
repositoryA.deleteByBook(Book);
}
Then
javax.persistence.TransactionRequiredException
would be thrown, with exception message:
No transactional EntityManager available