spring-transactions

Spring managed Transaction commits where it shouldn't

耗尽温柔 提交于 2019-12-11 11:56:18
问题 in "applicationContext-base.xml" I add below: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xsi

Spring managed transactions @Transactional annotation

为君一笑 提交于 2019-12-11 11:02:25
问题 Propagation setting is REQUIRED. @Transactional(propagation = Propagation.REQUIRED) Transaction is read/write. In which scenario those are used? Please give me explain with example 回答1: Spring transaction default is @Transactional(propagation = Propagation.REQUIRED) So you do not need to specify the propagation property. So, What does it mean by @Transactional annotation for a spring component ? Spring framework will start a new transaction and executes all the method and finally commit the

Null EntityManager using @PersistenceContext

戏子无情 提交于 2019-12-11 07:34:34
问题 I'm trying to use a simple coding with Spring Boot, using the @PersistenceContext in the entitymanager, to create a object in MySQL, but I'm getting that my entitymanager object is null and not sure why, because the method that is using the entitymanager hast the @transaction annotation. This is my code where I call the method to insert the data: import org.hibernate.service.spi.ServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework

How to define rollback transactions which are called inside of a loop with spring aop?

百般思念 提交于 2019-12-11 04:09:38
问题 Previously I have created a method updateRecord() in com.TestTransaction class. The updateRecord() method has a for loop to insert values into database. If there is any exception thrown inside the loop all the inserted values will rollback. This works fine and code is like below: Inside the java class file public class com.TestTransaction{ ... //this is a big transaction public void updateRecord(){ for(int i=0;i<5;i++){ //insert value to database... //...if a runtime exception thrown here, /

Transaction doesn't work in aspectj

耗尽温柔 提交于 2019-12-11 04:06:23
问题 I have the aspect(see below) which should log actions(create, update, delete) in db. Depends on action logging happens in a preProcess or postProcess method. I shouldn't log anything if some fail happens through these actions. I.e. if create didn't happened, then there is no need to logging it. I tried to tested it. I throw RunTimeException in the join point and expect that there is no new log in db. Unfortunately, new log is saved in spite of exception in the join point. Aspect: @Component

Spring Annotation driver Transaction with AspectJ problem

若如初见. 提交于 2019-12-11 02:23:01
问题 i am using AspectJ compile time weaving and spring 3.O. and Hibernate 3.0...AspectJ weaving is working fine for simple things like logging but this is not working correctly for Transaction <tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" order="1" /> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> Sprong-aspects jar is also

Serializable transactions not protecting me from double inserts

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 00:58:35
问题 In my scenario, a process engine allows only one instance of a process execution to be run at the same time, refusing others. Since my application is planned to be deployed to clusters, it is important that decisions taken in a node reflect the global system status. I understand that there are plenties of ways to achieve my goal. For that we are implementing a database lock leveraging standard ACID transactions. We have a table PROCESS_RUNS where we record current and historical executions.

Using Spring, why can H2 transaction rollback work correctly in embedded-database mode, but not in server mode?

落花浮王杯 提交于 2019-12-10 18:09:30
问题 A simple spring service with method doing insert and throwing Runtime exception after insert. Runtime exception should cause rollback. @Transactional() public void insertAndThrowRuntimeEx() { Order order = new Order(); entityManager.persist(order); throw new RuntimeException("Unexpected runtime exception"); } Rollback appears correctly only when I configure dataSource with: <jdbc:embedded-database id="dataSource" type="H2" /> <!-- with this configuration there is correct rollback --> But when

can @Order be applied on @Transactional?

混江龙づ霸主 提交于 2019-12-10 17:24:19
问题 I have a method which is annotated with @Transactional and another custom annotation @Custom. This custom annotation is wrapped around an advice. The sequence of operation is like below: 1.Transactional method gets called 2.Sees @Transactional and @Custom 3.As @Custom is intercepted by around advice, it first executes code before invocation of method 4.invocationContext.proceed() 5.Transaction gets created 6.Actual method runs 7.Back to around advice and executes code after method invocation

Get is not valid without active transaction

╄→гoц情女王★ 提交于 2019-12-10 11:58:26
问题 i have a trouble opening Hibernate transaction. This is the configuration: <context:annotation-config /> <context:component-scan base-package="com.cinebot" /> <mvc:annotation-driven /> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.cinebot.db.entity</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate