I would like to ignore the exception and commit the transaction anyway. However, every time I get a error. What exactly is the problem and how can I solve it?
@Transactional( noRollbackFor = EmptyResultDataAccessException.class )
public Foo foo( Foo foo, String barId ) {
Foo foo = fooRepository.save(foo)
deleteBarSilently(barId)
return foo ;
}
//@Transactional( noRollbackFor = EmptyResultDataAccessException.class )
private void deleteBarSilently( final String barId) {
try {
barRepository.deleteById( barId);
} catch ( final EmptyResultDataAccessException ignored ) {
System.out.println( ignored );
}
}
Error is: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction "rolled back" because transaction was set to RollbackOnly.
Exception is EmptyResultDataAccessException
EDIT: Also tried it with try/catch and without and with a array of exception @Transactional( noRollbackFor = {EmptyResultDataAccessException.class} ) and with fullqualified class name
Log without catch
Application exception overridden by commit exception
org.springframework.dao.EmptyResultDataAccessException: No class com.bosch.bci.foundation.digitaltwin.repository.domain.ModelReference entity with id c16675da-f5ce-46b1-97e6-7eb6869940aa exists!
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.lambda$deleteById$0(SimpleJpaRepository.java:166) ~[spring-data-jpa-2.5.3.jar:2.5.3]
Log with catch is just
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction "rolled back" because transaction was set to RollbackOnly.