• DispatcherServlet에도 transation 세팅을 해줘야한다.

( Application Context의 설정이 DispatcherServlet의 설정과 공유되는것이 아니기때문에 각각 해줘야함. )



try catch 문으로 되어있으면 exception이 catch문에서 printStackTrace로 잡히기 때문에

public class UserMapperDaoImpl implements UserMapperDao{

	private SqlSession sqlSession;
	//gettter and setter for sqlSession
	@Override
	public void saveUser(User user) {
		// TODO Auto-generated method stub
		try {	
			UserMapperDao userMapper=sqlSession.getMapper(UserMapperDao.clas s);
			userMapper.saveUser(user);
			if(user.getName().equalsIgnoreCase("abc")){
				throw new Exception("Simulate Error...");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

} catch(Exception e) {

e.printStackTrace();

thows new RuntimeException();

}


OR 


Try catch 문을 없애고 


public FourPillarsData getSajuFourPillars(FourPillarsInputData inputData) throws Exception{


이렇게 처리한다.




확인방법 


트랜잭션 처리가 되었으면,


DEBUG: org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
DEBUG: org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@304648]


처리가 되지 않았으면,


DEBUG: org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
DEBUG: org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1a51312] was not registered for synchronization because synchronization is not active



그리고 DefaultSqlSession 객체 주소가 각각의 프로세스 처리 Session 아이디와 같아야 된다


그래야만 롤백할때 한번에 날릴수있다.





참고


http://forum.spring.io/forum/spring-projects/data/125994-transaction-not-rolling-back-in-spring-mybatis-mysql

http://lunal.tistory.com/entry/spring-mybatis-%ED%8A%B8%EB%9E%9C%EC%9E%AD%EC%85%98-%EC%84%A4%EC%A0%95

+ Recent posts