spring-transactions

JUnit rollback transaction with @Async method

只愿长相守 提交于 2019-12-05 01:10:18
问题 I am writing an integration test using SpringJUnit4ClassRunner . I have a base class: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration({ /*my XML files here*/}) @Ignore public class BaseIntegrationWebappTestRunner { @Autowired protected WebApplicationContext wac; @Autowired protected MockServletContext servletContext; @Autowired protected MockHttpSession session; @Autowired protected MockHttpServletRequest request; @Autowired protected MockHttpServletResponse

Hibernate transaction manager configurations in Spring

╄→гoц情女王★ 提交于 2019-12-05 01:08:31
In my project I use Hibernate with programmatic transaction demarcation. Every time in my Service methods i write something similar to this. Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); .. perform operation here session.getTransaction().commit(); Now i'm going to refactor my code with declarative transaction management. What i got now ... <context:component-scan base-package="package.*"/> <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg

How to configure mutliple transaction managers with Spring + DBUnit + JUnit

风格不统一 提交于 2019-12-05 00:30:32
问题 In a nutshell My command line Java application copies data from one datasource to another without using XA. I have configured two separate datasources and would like a JUnit test that can rollback data on both datasources. I use DBUnit to load data into the "source" database, but I cannot get this to rollback. I can get the "target" datasource to rollback. My Code Given this config... <tx:annotation-driven /> <!-- note the default transactionManager name on this one --> <bean id=

java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor Error

自作多情 提交于 2019-12-04 22:25:34
I'm trying to configure <tx:annotation-driven /> in web.xml under a tomcat project using tomcat 6 and postgresql 9.1 My dispacher-Servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www

Spring:Propagation.REQUIRED not working

戏子无情 提交于 2019-12-04 19:20:25
I am inserting records in a couple of tables namely Dept and Emp . If the Dept table is successfully created then only I want to insert records in Emp table. Also, if any of the insert in Emp fails, then I want to rollback all the transaction which includes both rollback from Emp as well as Dept tables. I tried this using Propagation.REQUIRED as shown below: Java File public void saveEmployee(Employee empl){ try { jdbcTemplate.update("INSERT INTO EMP VALUES(?,?,?,?,?)",empl.getEmpId(),empl.getEmpName(), empl.getDeptId(),empl.getAge(),empl.getSex()); } catch (DataAccessException e) { e

Nested @Transactional methods with @Async

你。 提交于 2019-12-04 19:13:23
问题 I'm using Spring with JPA. I have @EnableAsync and @EnableTransactionManagement turned on. In my user registration service method, I have a few other service methods I call that are annotated @Async . These methods do various things like sending a welcome email and registering the newly minted user with our third party payment system. Everything works well until I want to verify that the third party payment system successfully created the user. At that point, the @Async method attempts to

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

牧云@^-^@ 提交于 2019-12-04 17:01:33
问题 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

Intercept transaction only when is sure to be committed but before is committed

北战南征 提交于 2019-12-04 16:20:05
问题 Context is Java - JPA with Hibernate and Spring. Let's take the scenario of two-phase commit protocol (but only with one resource): Query to commit from application Vote Yes/No (from database in our case) 3.1. If yes from database 3.1.1. ( Make callback in code ) - not part of the protocol 3.1.2. Commit to database 3.2 If no 3.2.1 Rollback to database What I want is a way to do the callback from 3.1.1 in code, but only when it is known that the transaction will be committed, but before is

Transaction Management in Spring 3.x and Hibernate 4

北战南征 提交于 2019-12-04 14:37:57
问题 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:

Upgraded from Spring 4.1.6 to 4.2.4 and suddenly getting TransactionRequiredException

寵の児 提交于 2019-12-04 12:48:35
I have upgraded to latest Spring version from 4.1.6.Release to 4.2.4.Release and suddenly all what has functioned smoothly before, now throws the following exception. javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:277) ~[na:4.2.4.RELEASE] at com.sun.proxy.$Proxy51.persist(Unknown Source) ~[na:na] Interceptor.class public class MessageInterceptor