The project test had a problem, the method ended normally, but reported
Could not commit JPA transaction, nested exception is javax.persistence.RollbackException:Transaction marked as ROLLB Ackonly org.springframework.transaction.TransactionSystemException:Could not commit JPA transaction; Nested exception is javax.persistence.RollbackException:Transaction marked as rollbackonly at Org.springframework.orm. Jpa. Jpatransactionmanager.docommit (Jpatransactionmanager.java:521) at Org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit ( Abstractplatformtransactionmanager.java:754) at Org.springframework.transaction.support.AbstractPlatformTransactionManager.commit ( Abstractplatformtransactionmanager.java:723) at Org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning ( Transactionaspectsupport.java:393) at Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (Transactioninterceptor.java: 120) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (Reflectivemethodinvocation.java: 172) at Org.springframework.aop.framework.cglib2aopproxy$dynamicadvisedinterceptor.intercept ( Cglib2aopproxy.java:622)
Error, ask what can not be submitted?
After the search, I found this passage.
I finally understood the Problem:methoda () {MethodB ()} @Transactional (norollbackfor = Exception. class try {METHODC ()} catch (...) {...} Log ( OK );} @TransactionalmethodC () { throw new ... ();} What happens was that even though the MethodB have the right annotation, the METHODC does not. When the exception are thrown, the second @Transactional marks the first transaction as Rollback only anyway.
Originally, in a transactional if there is another transaction exception, even if you catch the exception, then transaction will also be defined as rollbackonly, which is the principle of transaction management, but my system where the exception?
Originally, the Spring JPA Jparepository implementation method with the ID deleted by the source code is this
@Transactional Public void Delete (ID ID) { assert.notnull (ID, id_must_not_be_null); = FindOne (ID); if NULL ) { thrownew emptyresultdataaccessexception (String.Format ("No%s entity with ID%s exists! " , 1); } Delete (entity); }
He did so by looking for the object of this ID to see if there is a non-checked exception that is thrown directly if it does not exist, and the delete operation is no longer performed. This is not the same as what I used to think, generally I am accustomed to delete no records will not error, the implementation of SQL is also the case. And I just caught this anomaly outside, so the problem happened.
Resolve could not commit JPA transaction rollbackexception:transaction marked as Rollbackonly