JAVA
트랜잭션 관리
9400
2023. 2. 10. 17:24
root-context 추가
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!--
트랜잭션 : 데이터베이스를 변경하기 위해 수행되어야할 논리적 단위. 여러개의 sql로 구성됨
원자성, 일관성, 고립성(격리성), 지속성(영속성)
-->
<!-- 트랜잭션 관리자의 자바빈을 정의함 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 애너테이션 기반의 트랜잭션 제어를 활성화함 -->
<tx:annotation-driven/>
어노테이션
@Transactional
//고객(CUS)등록 + 소유자돋차등록
@Transactional
@Override
public int createPost(CusVO cusVO) {
int result = 0;
//1. 고객(CUS) 등록(1행)
result= this.cusMapper.createPost(cusVO);
//2. 소유자동차(CAR) 등록(N행)
List<CarVO> carVOList = cusVO.getCarVOList();
List<CarVO> carVOListNew = new ArrayList<CarVO>();
//cusNum 최신화
for(CarVO carVO : carVOList) {
carVO.setCusNum(cusVO.getCusNum());
carVOListNew.add(carVO);
}
result = result + this.cusMapper.createPostcar(carVOListNew);
log.info("result : "+result);
return result;
}
알아서 트랜잭션