spring-transactions

Does Spring @transaction work on a concrete method of abstract class

情到浓时终转凉″ 提交于 2019-12-03 11:05:21
From spring reference doc Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), then the transaction settings are not

Transaction Management in Spring 3.x and Hibernate 4

风格不统一 提交于 2019-12-03 09:08:18
Hi I have faced a wall while I was trying to do transaction management using Spring 3.x and Hibernate 4. I've searched on the Internet but there were ways to do this in Hibernate 3, not so many in Hibernate 4. I'm quite confused and I'm not sure if this setting is working. Things I'm using... Spring 3.x Hibernate 4 I've read these http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html#transaction-declarative spring, hibernate and declarative transaction implementation: there is no active transaction and some more... Follow up I've managed to run my classes successfully. I

Spring nested transactions

老子叫甜甜 提交于 2019-12-03 06:46:05
问题 In my Spring Boot project I have implemented following service method: @Transactional public boolean validateBoard(Board board) { boolean result = false; if (inProgress(board)) { if (!canPlayWithCurrentBoard(board)) { update(board, new Date(), Board.AFK); throw new InvalidStateException(ErrorMessage.BOARD_TIMEOUT_REACHED); } if (!canSelectCards(board)) { update(board, new Date(), Board.COMPLETED); throw new InvalidStateException(ErrorMessage.ALL_BOARD_CARDS_ALREADY_SELECTED); } result = true;

Synchronising transactions between database and Kafka producer

点点圈 提交于 2019-12-03 05:04:26
问题 We have a micro-services architecture, with Kafka used as the communication mechanism between the services. Some of the services have their own databases. Say the user makes a call to Service A, which should result in a record (or set of records) being created in that service’s database. Additionally, this event should be reported to other services, as an item on a Kafka topic. What is the best way of ensuring that the database record(s) are only written if the Kafka topic is successfully

Roll back A if B goes wrong. spring boot, jdbctemplate

旧城冷巷雨未停 提交于 2019-12-03 02:51:53
问题 I have a method, 'databaseChanges', which call 2 operations: A, B in iterative way. 'A' first, 'B' last. 'A' & 'B' can be C reate, U pdate D elete functionalities in my persistent storage, Oracle Database 11g. Let's say, 'A' update a record in table Users, attribute zip, where id = 1. 'B' insert a record in table hobbies. Scenario: databaseChanges method is been called, 'A' operates and update the record. 'B' operates and try to insert a record, something happen, an exception is been thrown,

Spring transaction REQUIRED vs REQUIRES_NEW : Rollback Transaction

只愿长相守 提交于 2019-12-03 00:37:11
问题 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,

SourcePollingChannelAdapter with Transaction

本秂侑毒 提交于 2019-12-02 20:45:47
问题 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

Synchronising transactions between database and Kafka producer

最后都变了- 提交于 2019-12-02 18:23:39
We have a micro-services architecture, with Kafka used as the communication mechanism between the services. Some of the services have their own databases. Say the user makes a call to Service A, which should result in a record (or set of records) being created in that service’s database. Additionally, this event should be reported to other services, as an item on a Kafka topic. What is the best way of ensuring that the database record(s) are only written if the Kafka topic is successfully updated (essentially creating a distributed transaction around the database update and the Kafka update)?

Roll back A if B goes wrong. spring boot, jdbctemplate

房东的猫 提交于 2019-12-02 17:20:07
I have a method, 'databaseChanges', which call 2 operations: A, B in iterative way. 'A' first, 'B' last. 'A' & 'B' can be C reate, U pdate D elete functionalities in my persistent storage, Oracle Database 11g. Let's say, 'A' update a record in table Users, attribute zip, where id = 1. 'B' insert a record in table hobbies. Scenario: databaseChanges method is been called, 'A' operates and update the record. 'B' operates and try to insert a record, something happen, an exception is been thrown, the exception is bubbling to the databaseChanges method. Expected: 'A' and 'B' didn't change nothing.

How to configure AspectJ with Load Time Weaving without Interface

折月煮酒 提交于 2019-12-02 15:59:15
On my project, I currently use AspectJ (not just Spring AOP due to some limitation) with the weaving at the Compile Time. In order to speed up the development on Eclipse, I want to do the weaving at the Load Time. I succeed to do that but with one major constraint: using an interface for my service that contained some transactional methods. If I declare the service with its implementation instead of its interface, in the caller class, there is no weaving and so no transaction supported. So if it is supported by AspectJ, how to configure AspectJ with Load Time Weaving without Interface ? I