spring-transactions

Spring transaction REQUIRED vs REQUIRES_NEW : Rollback Transaction

旧时模样 提交于 2019-12-02 14:14:13
I have a method that has the propagation = Propagation.REQUIRES_NEW transactional property: @Transactional(propagation = Propagation.REQUIRES_NEW) public void createUser(final UserBean userBean) { //Some logic here that requires modification in DB } This method can be called multiple times simultaneously, and for every transaction if an error occurs than it's rolled back (independently from the other transactions). The problem is that this might force Spring to create multiple transactions, even if another one is available, and may cause some performance problems. Java doc of propagation =

Confusion between @Transactional and AOP

余生长醉 提交于 2019-12-02 08:11:44
Does @Transactional is replacement for AOP in spring 3. are they same? Can I say @Transactional implements AOP internally ? The @Transactionnal annotation is just a simple way to declare that a method is (or all methods of a class are) transactionnal. The Spring Framework will use an AOP proxy to intercept calls to the method and manage transaction. So, we can say that @Transactionnal use AOP internally. More information here What you can say is that Spring uses AOP to add a transactional aspect to bean methods annotated with @Transactional : before executing such a method, it starts a

SourcePollingChannelAdapter with Transaction

馋奶兔 提交于 2019-12-02 07:55:46
I would like to use a SourcePollingChannelAdapter with a transaction propagation REQUIRED when the polling is realized, to rollback all operations if an error is occured. The method setTransactionSynchronizationFactory is not commented... Thanks a lot for your help ! In XML I can do : <int:poller fixed-rate="5000"> <int:transactional transaction-manager="transactionManager" propagation="REQUIRED" /> </int:poller> I would like to use a transaction like this programmatically with a SourcePollingChannelAdapter and a PeriodicTrigger, but I don't know how. I have this : SourcePollingChannelAdapter

Spring new transaction combined with Retryable

末鹿安然 提交于 2019-12-02 03:44:38
If I have a method that has a Spring retryable for a certain exception, and also has a Transactional(Requires_new), every time the retry is done, will it create a new transaction or use the existing one? ie @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 250), include = {ActivitiOptimisticLockingException.class}) @Transactional(propagation = Propagation.REQUIRES_NEW) public void setVariable(String processId, String variableName, String variableValue){ engine.getRuntimeService().setVariable(processId, variableName, variableValue); } What will actually happen here? will be created new

Spring new transaction combined with Retryable

怎甘沉沦 提交于 2019-12-02 03:06:42
问题 If I have a method that has a Spring retryable for a certain exception, and also has a Transactional(Requires_new), every time the retry is done, will it create a new transaction or use the existing one? ie @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 250), include = {ActivitiOptimisticLockingException.class}) @Transactional(propagation = Propagation.REQUIRES_NEW) public void setVariable(String processId, String variableName, String variableValue){ engine.getRuntimeService()

How to rollback a transaction if the POST response could not be delivered

流过昼夜 提交于 2019-12-02 00:51:48
Using Spring MVC, assume I have implemented a controller that handles a POST request, performs a database operation inside a transaction, and returns a result in the response body. Here is the controller and service layer: @RestController @RequiredArgsConstructor public class SomeController { private final SomeService someService; @PostMapping("/something") public SomeResult postSomething(Something something) { return someService.handle(something); } } @Service @RequiredArgsConstructor public class SomeService { private final SomeRepository someRepository; @Transactional public SomeResult

Spring Transactions - Prevent rollback after unchecked exceptions (RuntimeException)

随声附和 提交于 2019-12-01 22:39:14
I can't manage to prevent a transaction from rollingback after a RuntimeException. My env is Spring 4.1 + Hibernate 3.6 + JTA (WebSphereUowTransactionManager) running on Websphere 8.0. First off, a simple case that behaves as expected. Since I catch the RuntimeException , the transaction commits and the new resource is created successfully. @Service("fooService") public class FooServiceImpl implements IFooService { @Transactional @Override public void doStuff(Resource res){ authService.createResource(res, "ADMIN"); try { throw new RuntimeException("SOMETHING"); } catch (RuntimeException e) { e

Isolation level SERIALIZABLE in Spring-JDBC

谁说胖子不能爱 提交于 2019-12-01 19:28:56
maybe somebody can help me with a transactional issue in Spring (3.1)/ Postgresql (8.4.11) My transactional service is as follows: @Transactional(isolation = Isolation.SERIALIZABLE, readOnly = false) @Override public Foo insertObject(Bar bar) { // these methods are just examples int x = firstDao.getMaxNumberOfAllowedObjects(bar) int y = secondDao.getNumerOfExistingObjects(bar) // comparison if (x - y > 0){ secondDao.insertNewObject(...) } .... } The Spring configuration Webapp contains: @Configuration @EnableTransactionManagement public class ....{ @Bean public DataSource dataSource() { org

Spring Transactions - Prevent rollback after unchecked exceptions (RuntimeException)

我怕爱的太早我们不能终老 提交于 2019-12-01 19:21:08
问题 I can't manage to prevent a transaction from rollingback after a RuntimeException. My env is Spring 4.1 + Hibernate 3.6 + JTA (WebSphereUowTransactionManager) running on Websphere 8.0. First off, a simple case that behaves as expected. Since I catch the RuntimeException , the transaction commits and the new resource is created successfully. @Service("fooService") public class FooServiceImpl implements IFooService { @Transactional @Override public void doStuff(Resource res){ authService

Testing @TransactionalEvents and @Rollback

房东的猫 提交于 2019-12-01 08:57:55
I've been trying to test out @TransactionalEvents (a feature of Spring 4.2 https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2 ) with our existing Spring JUnit Tests (run via either @TransactionalTestExecutionListener or subclassing AbstractTransactionalUnit4SpringContextTests but, it seems like there's a forced choice -- either run the test without a @Rollback annotation, or the events don't fire. Has anyone come across a good way to test @TransactionalEvents while being able to @Rollback tests? Stéphane Nicoll is correct: if the TransactionPhase for your