在我的Spring Boot应用程序中,我遇到了事务支持问题。如果函数dodajRezerwacje(),但数据库中的记录发生了更改,则会出现异常。
我验证了所有的服务,它们都有@Transactional注解。我在application.properties中添加了"springframework.transaction=DEBUG“来查找问题,但我没有。
App.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;
}
...
}
我的DEBUG.log:
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行得到了一个异常(我是有预谋地检查事务的,这不是一个bug),数据被保存/更新在Rezerwacja,CCard和Historiaop表中。当此方法中发生异常时,我希望回滚事务。
发布于 2019-01-09 20:34:18
@ transactions仅回滚未检查异常的事务。如果抛出异常或其子类,并且希望在发生检查异常时回滚,则使用此
@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)
发布于 2019-01-09 21:33:35
为了便于故障排除和代码的可维护性,使用方法级@Transactional注解总是很好的做法。只有当应用程序抛出未检查的异常时,才会发生回滚。在你的方法上添加:@Transactional(rollbackFor = Exception.class)
将允许你触发回滚。
https://stackoverflow.com/questions/54110034
复制相似问题