java - 我的 Spring Boot 中的事务出现问题 - 我遇到异常,但事务正在提交

标签 java hibernate spring-boot transactions

我的 Spring Boot 应用程序中存在事务支持问题。如果函数 dodajRezerwacje() 出现异常,但数据库中的记录已更改。

我验证了所有服务,它们都有 @Transactional 注释。我在 application.properties 中添加了“springframework.transaction=DEBUG”来查找问题,但我没有。

应用程序.java:

@SpringBootApplication
@EnableJpaRepositories(basePackages = "ekoncept.dao")
@ComponentScan(value = "ekoncept.*")
@EntityScan("ekoncept.model.entity")
@EnableScheduling
public class App
{
    public static void main( String[] args ) {

        SpringApplication.run(App.class, args);
    }
}

EntityManagerFactoriesConfig.java:

@Configuration
public class EntityManagerFactoriesConfig {

    @Autowired
    private DataSource dataSource;

    @Bean(name = "entityManagerFactory")
    public LocalContainerEntityManagerFactoryBean emf() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(dataSource);
        emf.setPackagesToScan(
                new String[]{"ekoncept"});             // czy cały pakiet?? nie wiem...
        emf.setJpaVendorAdapter(
                new HibernateJpaVendorAdapter());
        return emf;
    }
}

TransactionManagersConfig.java:

@EnableTransactionManagement
public class TransactionManagersConfig {
    @Autowired
    EntityManagerFactory emf;
    @Autowired
    private DataSource dataSource;

    @Bean(name = "transactionManager")
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager tm =
                new JpaTransactionManager();
        tm.setEntityManagerFactory(emf);
        tm.setDataSource(dataSource);
        return tm;
    }
}

RezerwacjaManager.java:

@Service
@Transactional
public class RezerwacjaManager {
...
public boolean edytujRezerwacje(String input, AuthUser user)
            throws IOException, RecordIdNotFoundException, ParamValueNotValidException, ParseException, RecordIdNotAllowedException,
            RecordNotExistsException, MethodParamMissingException, RequiredFieldNotFoundException,
            CCardNotModificableException, OnlinePaymentErrorException {

        logMgr.logJsonInput("edytujRezerwacje", input);

        Rezerwacja rez = (Rezerwacja) rezFact.getUpdatedObject(input);
        org.json.JSONObject jsonObj = new org.json.JSONObject(input);

        if (jsonObj.has("CCard")) {     // THIS OPERATIONS ARE SAVED IN DB  (insert into table CCard + delete from tabele Ccard + update table Rezerwacja)                                           
            Ccard oldCC = null;
            if (rez.getCcardId() != null) {    // karta została już wprowadzona
                oldCC = ccardDao.findOne(rez.getCcardId());
                if (oldCC != null && oldCC.getCcardVerified() == 1) {
                    throw new CCardNotModificableException("karta została zweryfikowana");
                }
            }
            String ccNumer = "";
            org.json.JSONObject ccObj = jsonObj.getJSONObject("CCard");
            Ccard cc = (Ccard) ccardFact.getNewObject(ccObj.toString());
            ccardDao.save(cc);
            histMgr.logToHistoryCCard(cc.getCcardId(), rez.getRezerwacjaId(), null, user, Operacja.NOWY_REKORD);

            if (oldCC != null) {                             // usunięcie starych danych
                histMgr.logToHistoryCCard(oldCC.getCcardId(), rez.getRezerwacjaId(), null, user, Operacja.USUNIECIE_DANYCH);
                ccardDao.delete(oldCC);
            }
            rez.setCcardId(cc.getCcardId());
        }

        if (jsonObj.has("Platonline")) {   // NOT EXECUTING IN THIS CASE
            ....
        }

        rezDao.save(rez);                                               // THIS OPERATIONS ARE SAVED IN DB (update table Rezerwacja)  
        histMgr.logToHistory(rez, user, Operacja.MODYFIKACJA_DANYCH);   // THIS OPERATIONS ARE SAVED IN DB (insert into table Historiaop)

        if (jsonObj.has("Rezerwacjaosoba")) {
            ....
        }
        if (jsonObj.has("Usluga")) {
            ....                        // !!! HERE I GOT AN EXCEPTION !!!
        }
        return true;
    }
...
}

我的调试日志:

2019-01-09 12:54:48 - Bound request context to thread: org.apache.catalina.connector.RequestFacade@4869f607
2019-01-09 12:54:48 - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Creating new transaction with name [ekoncept.service.RezerwacjaManager.edytujRezerwacje]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2019-01-09 12:54:48 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@3896d31d]
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Rezerwacja rezerwacja0_ where rezerwacja0_.REZERWACJA_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Pokoj pokoj0_ where pokoj0_.POKOJ_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Pokojtyp pokojtyp0_ where pokojtyp0_.POKOJTYP_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Asort asort0_ where asort0_.ASORT_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from OSOBA osoba0_ where osoba0_.OSOBA_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Usluga usluga0_ where usluga0_.USLUGA_DOMYSLNA=-1 and (usluga0_.REZERWACJA_ID=? or ? is null) and (usluga0_.MELDUNEK_ID=? or ? is null)
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[EntityKey[ekoncept.model.entity.Rezerwacja#81997], EntityKey[ekoncept.model.entity.Pokoj#-3], EntityKey[ekoncept.model.entity.Pokojtyp#3], EntityKey[ekoncept.model.entity.Osoba#35054], EntityKey[ekoncept.model.entity.Asort#24]],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Ccard ccard0_ where ccard0_.CCARD_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select gen_id( SEQ_CCARD, 1 ) from RDB$DATABASE
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=1} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=1} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=1} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=1} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select gen_id( SEQ_HISTORIAOP, 1 ) from RDB$DATABASE
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=2} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=2} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=2} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=2} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select gen_id( SEQ_HISTORIAOP, 1 ) from RDB$DATABASE
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=3} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=3} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=3} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=3} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select gen_id( SEQ_HISTORIAOP, 1 ) from RDB$DATABASE
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select rezerwacja0_.OSOBA_ID as OSOBA_ID1_148_, rezerwacja0_.REZERWACJA_ID as REZERWAC2_148_ from Rezerwacjaosoba rezerwacja0_ where rezerwacja0_.REZERWACJA_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Rezerwacjaosoba rezerwacja0_ where rezerwacja0_.REZERWACJA_ID=? and rezerwacja0_.OSOBA_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Usluga usluga0_ where usluga0_.REZERWACJA_ID=?
2019-01-09 12:54:48 - Found thread-bound EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])] for JPA transaction
2019-01-09 12:54:48 - Participating in existing transaction
2019-01-09 12:54:48 - select ... from Usluga usluga0_ where usluga0_.USLUGA_ID=?
2019-01-09 12:54:48 - Initiating transaction commit
2019-01-09 12:54:48 - Committing JPA transaction on EntityManager [SessionImpl(PersistenceContext[entityKeys=[...],collectionKeys=[]];ActionQueue[insertions=ExecutableList{size=4} updates=ExecutableList{size=0} deletions=ExecutableList{size=1} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2019-01-09 12:54:48 - insert into Ccard ...
2019-01-09 12:54:48 - insert into Historiaop ...
2019-01-09 12:54:48 - insert into Historiaop ...
2019-01-09 12:54:48 - insert into Historiaop ...
2019-01-09 12:54:48 - update Rezerwacja set ... where REZERWACJA_ID=?
2019-01-09 12:54:48 - delete from Ccard where CCARD_ID=?
2019-01-09 12:54:48 - Not closing pre-bound JPA EntityManager after transaction
2019-01-09 12:54:48 - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2019-01-09 12:54:48 - Closing JPA EntityManager
2019-01-09 12:54:48 - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@4869f607
2019-01-09 12:54:48 - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2019-01-09 12:54:48 - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2019-01-09 12:54:48 - Closing JPA EntityManager

我在 294 行遇到了异常(我是经过预谋来检查交易的,这不是一个错误),并且数据在 Rezerwacja、CCard 和 Historiaop 表中保存/更新。 当此方法发生异常时,我希望回滚事务。

最佳答案

@Transactional 仅针对未检查的异常回滚事务。 如果您抛出异常或其子类,并且希望在发生已检查异常时回滚,请使用此

@Transactional(rollbackFor = Exception.class) 

所以在方法之上

public boolean edytujRezerwacje(String input, AuthUser user)
            throws IOException, RecordIdNotFoundException, ParamValueNotValidException, ParseException, RecordIdNotAllowedException,
            RecordNotExistsException, MethodParamMissingException, RequiredFieldNotFoundException,
            CCardNotModificableException, OnlinePaymentErrorException {

添加以下内容

@Transactional(rollbackFor = Exception.class) 

关于java - 我的 Spring Boot 中的事务出现问题 - 我遇到异常,但事务正在提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54110034/

相关文章:

java - 对打印方法进行单元测试

java - 显示carrot2集群内容

java - spring boot zuul错误的请求重定向

java - 如何使用 hibernate 注释配置从 2 个模型类制作 Bridge 表

java - 如何将 Angular 6 项目和 Spring Boot 项目部署为单个部署单元

java - 在 Spring 中使用 HikariCP 连接到 Oracle DB 时发送应用程序名称

java - 用于 HTTPS 调用的 Apache Commons HttpClient

java - Windows 7 上的 JVM 核心转储文件位于何处?

java - 盒装与原始类型作为实体 id

java - 用于 Java 持久性的 JPA 或 Hibernate?