spring-transactions

How to manage the transaction(which includes File IO) when an IOException is thrown from the close file method

假装没事ソ 提交于 2021-02-18 22:07:07
问题 I've recently begun using Spring's Data Source Transaction Manager. I have a problem now. My transaction includes updates to a DB table and a write operation to a file. It works fine but I have some doubts about file I/O. As you see below, I have configured openFile and closeFile methods of my bean as the init-method and the destroy-method respectively, which in turn provides those methods to be called just like a constuructor and a destructor. If the file is not closed properly, some of the

Spring Transaction not rolling back

我与影子孤独终老i 提交于 2021-02-18 11:20:10
问题 I have something like this: @Service @Transactional public class ServiceA { @Autowired SomeDAO1 dao1; @Autowired ServiceB serviceB; public void methodServiceA() { serviceB.someMethodThatRunsInsertIntoDB(); dao1.anotherMethodThatRunsInsertIntoDB(); } } @Service @Transactional public class ServiceB { @Autowired Dao2 dao2; public void someMethodThatRunsInsertIntoDB() { dao2.insertXXX(); } } My problem is: if serviceB.someMethodThatRunsInsertIntoDB() executes sucessfully but dao1

No transactional EntityManager available Error

别来无恙 提交于 2021-02-11 14:30:41
问题 I have a below spring setup. Basically I am trying to configure two transaction managers here. One with hibernate and other with JPA. But somehow when I try to run JPA transaction manager, there I get "javax.persistence.TransactionRequiredException: No transactional EntityManager available" error. Appreciate if somebody finds the problem in below code. data-context.xml file as below <bean id="fundBO" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"

Continue with transaction after exception - JPA

ぃ、小莉子 提交于 2021-02-07 12:40:39
问题 I am using JPA with Spring. I am trying to do batch import. If there is problem with batch import then I would like to insert individually, and if this fails also then I would like to save to duplicates table. I wrote a logic for this but I get this error everytime: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly Mine setting for JPA are like this: @Bean(name = "dataSource", destroyMethod = "") public DataSource

javax.persistence.TransactionRequiredException: no transaction is in progress, @Transactional(propagation=Propagation.REQUIRED) not working

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-04 05:04:10
问题 Whenever I try to entityManager.flush() I get the error mentioned on title. That is interesting that all my models have been created properly on MySql during application start up. I have read several questions with similar exception and basically all of them point to use/change @Transaction somehow. Any suggestion or even a scratch idea about what to check will be highly appreciated. I don't think it is really relevant but let me inform btw: I am using WebSphere Liberty Profile + MySql. where

javax.persistence.TransactionRequiredException: no transaction is in progress, @Transactional(propagation=Propagation.REQUIRED) not working

爱⌒轻易说出口 提交于 2021-02-04 05:03:23
问题 Whenever I try to entityManager.flush() I get the error mentioned on title. That is interesting that all my models have been created properly on MySql during application start up. I have read several questions with similar exception and basically all of them point to use/change @Transaction somehow. Any suggestion or even a scratch idea about what to check will be highly appreciated. I don't think it is really relevant but let me inform btw: I am using WebSphere Liberty Profile + MySql. where

How to lock on select and release lock after update is committed using spring?

左心房为你撑大大i 提交于 2021-01-29 06:07:57
问题 I have started using spring from last few months and I have a question on transactions. I have a java method inside my spring batch job which first does a select operation to get first 100 rows with status as 'NOT COMPLETED' and does a update on the selected rows to change the status to 'IN PROGRESS'. Since I'm processing around 10 million records, I want to run multiple instances of my batch job and each instance has multiple threads. For a single instance, to make sure two threads are not

@TransactionalEventListener method not fired

落花浮王杯 提交于 2021-01-29 03:43:12
问题 I have a code where event is published in a method annotated with Spring @Transactional annotation. @Override @Transactional public Task updateStatus(Integer taskId, ExecutionStatus newStatus) { Task task = Task.builder().executionStatus(newStatus).build(); return updateStatusInternal(taskId, rteWithMetadata); } private TaskExecution updateStatusInternal(Integer taskId, Task newStatus) { Task task = taskService.findById(taskId); TaskExecution te = task.getFirstExecution(); TaskExecution

@TransactionalEventListener method not fired

 ̄綄美尐妖づ 提交于 2021-01-29 03:41:48
问题 I have a code where event is published in a method annotated with Spring @Transactional annotation. @Override @Transactional public Task updateStatus(Integer taskId, ExecutionStatus newStatus) { Task task = Task.builder().executionStatus(newStatus).build(); return updateStatusInternal(taskId, rteWithMetadata); } private TaskExecution updateStatusInternal(Integer taskId, Task newStatus) { Task task = taskService.findById(taskId); TaskExecution te = task.getFirstExecution(); TaskExecution

spring hibernate optimistic locking issue

淺唱寂寞╮ 提交于 2021-01-28 06:14:55
问题 This is my Repository layer: class RepositoryImpl implements Repository{ @Override public Serializable saveOrUpdate(Object obj) { return getSession().save(obj); } @Override public Object get(Class refClass, Serializable key) { return getSession().get(refClass, key); } } This is my Service layer: class ServiceImpl implements Service{ @Autowired Repository repository; @Override @Transactional public Object findUserById(Serializable key) { // TODO Auto-generated method stub return repository.get