transactional

@Transactional annotation works with saveAndFlush?

梦想的初衷 提交于 2020-06-24 22:21:09
问题 I have the following implementation. @Transactional public void saveAndGenerateResult(Data data) { saveDataInTableA(data.someAmountForA); saveDataInTableB(data.someAmountForB); callAnAggregatedFunction(data); } public void saveDataInTableA(DataA a) { tableARepository.saveAndFlush(a); } public void saveDataInTableA(DataB b) { tableBRepository.saveAndFlush(b); } public void callAnAggregatedFunction() { // Do something based on the data saved from the beginning in Table A and Table B } It is

@transactional 使用注意事宜

自古美人都是妖i 提交于 2020-04-18 06:46:48
1. 在需要事务管理的地方加@Transactional 注解。@ Transactional 注解可以被应用于接口定义和接口方法、类定义和类的 public 方法上 。 2. @Transactional 注解只能应用到 public 可见度的方法上 。 如果你在 protected、private 或者 package-visible 的方法上使用 @Transactional 注解,它也不会报错, 但是这个被注解的方法将不会展示已配置的事务设置。 3. 注意仅仅 @Transactional 注解的出现不足于开启事务行为,它仅仅 是一种元数据。必须 在配置文件中使用配置元素,才真正开启了事务行为。 4. 通过 元素的 " proxy-target-class" 属性值来控制是基于接口的还是基于类的代理被创 建。 如果 "proxy-target-class" 属值被设置为 "true",那么基于类的代理将起作用(这时需要CGLIB库cglib.jar在CLASSPATH中)。如果 "proxy-target-class" 属值被设置为 "false" 或者这个属性被省略,那么标准的JDK基于接口的代理将起作用。 <!-- JTA事务(非分布式事务), 事务配置的时候 ,不能指定dataSource属性(分布式事务,是有全局事务来管理数据库链接的)--> <!--

Spring - @Transactional - What happens in background?

ぃ、小莉子 提交于 2020-03-05 04:05:12
问题 I want to know what actually happens when you annotate a method with @Transactional ? Of course, I know that Spring will wrap that method in a Transaction. But, I have the following doubts: I heard that Spring creates a proxy class ? Can someone explain this in more depth . What actually resides in that proxy class? What happens to the actual class? And how can I see Spring's created proxied class I also read in Spring docs that: Note: Since this mechanism is based on proxies, only 'external'

Alternatives to using Transactional NTFS

旧街凉风 提交于 2020-01-29 13:31:08
问题 Given that Microsoft has deprecated Transactional NTFS (TxF): Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows. While TxF is a powerful set of APIs, there has been extremely limited developer interest in this API platform since Windows Vista primarily

Nested @Transactional

对着背影说爱祢 提交于 2020-01-21 02:39:06
问题 Is it possible to nest @Transactional annotated methods in spring? Consider something like this: @Transactional public void a() { obj.b(); } @Transactional public void b() { // ... } What happens in such a case if I rollback in b() and rollback in a() ? 回答1: The second @Transactional annotation on method b() is not required because by default @Transactional has a propagation of REQUIRED , therefore methods called by method a() will be transactional. If you are looking to start a new

Spring @Transactional Annotation : Self Invocation

假装没事ソ 提交于 2020-01-19 10:03:26
问题 I know when a transactional method is called from inside the same class it wouldn't be run in a transaction. Spring creates a proxy for transactional methods and wraps them in a try-catch block and rolls back if an exception occurs. Consider the following scenario: @Transactional public void saveAB(A a, B b) { saveA(a); saveB(b); } @Transactional public void saveA(A a) { dao.saveA(a); } @Transactional public void saveB(B b) { dao.saveB(b); } Assume saveAB is called from another object and an

@Transactional propogate transactions only for a few exceptions

笑着哭i 提交于 2020-01-17 12:13:40
问题 I am trying to make a transaction fail for all the unchecked exceptions except for a particular unchecked exception(in my case - DuplicateKeyException). How can I achieve this customization using @Transactional annotation of Spring framework ? Thank you! 回答1: Try the noRollbackFor option @Transactional(noRollbackFor=DuplicateKeyException.class) 回答2: Do it like this : public void driverMethod(){ try{ BeforeException() } catch(DuplicateKeyException e) AfterException() } @Transactional

Centralized rollback-for using @transactional

点点圈 提交于 2020-01-15 05:04:08
问题 Is it possible to tell Spring to rollback for exception MyException as well as RuntimeException in the XML configuration while using @transactional ? I know it is possible to set the rollback for in the annotation but it seems redundant if I have lots of services that would all set the same exceptions. I saw peoples suggesting to create a custom transactional annotation but I'd prefer not to use a custom annotation and stick with a Spring one. I know that its possible to use advices but never

which SessionFactory should be use for transactionManager?

爱⌒轻易说出口 提交于 2020-01-14 03:43:50
问题 <bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> <property name="target"> <bean class="com.company.project.company.services.ServiceImpl" init-method="init"> <property name="HRappsdao" ref="HRappsdao"/> <property name="projectdao" ref="projectdao"/> </bean> </property> <property name="transactionAttributes"> <props> <prop key="store*">PROPAGATION_REQUIRED</prop> <prop key=

Spring @Transactional with synchronized keyword doesn't work

廉价感情. 提交于 2020-01-12 07:51:11
问题 Let's say I have a java class with a method like this (just an example) @Transactional public synchronized void onRequest(Request request) { if (request.shouldAddBook()) { if (database.getByName(request.getBook().getName()) == null) { database.add(request.getBook()); } else { throw new Exception("Cannot add book - book already exist"); } } else if (request.shouldRemoveBook()) { if (database.getByName(request.getBook().getName()) != null) { removeBook(); } else { throw new Exception("Cannot