JSF, Spring 및 Hibernate 프레임 워크를 사용하는 응용 프로그램을 작성 중입니다. 다음 메소드를 사용하여 Spring의 트랜잭션을 테스트하려고한다.예외가 잡히면 변경 사항을 롤백하기 위해 Spring의 트랜잭션을 사용하는 방법은 무엇입니까?
@Override
@Transactional(rollbackFor=UnsupportedOperationException.class, propagation=Propagation.REQUIRED)
public void updateActiveMonth(Long collectionMonthId) throws Exception{
try{
Session session = getSessionFactory().getCurrentSession();
String hql = "update CollectionMonth collectionMonth set active = false";
Query query = session.createQuery(hql);
query.executeUpdate();
if (true) {
throw new UnsupportedOperationException();
}
String hql1 = "update CollectionMonth collectionMonth set collectionMonth.active = true where collectionMonth.id=:collectionMonthId";
Query query1 = session.createQuery(hql1);
query1.setLong("collectionMonthId", collectionMonthId);
query1.executeUpdate();
}catch(UnsupportedOperationException e){
throw e;
}
}
위의 방법은 첫 번째 쿼리로 만든 업데이트를 롤백하는 것으로 가정하고 있지만 이는 발생하지 않습니다. 응용 프로그램의 맥락에서
내가 설정
다음 한<context:annotation-config/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
<!-- PERSISTENCE SUPPORT HERE (Hibernate 4 Mapping In Spring) -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="/WEB-INF/hibernate.cfg.xml"
p:packagesToScan="collection.model"/>
<!-- Transaction Manager is defined -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<!-- Enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
아무도 내가 뭘 잘못 말해 줄 수?
거래는 특별한 주석과도 롤백 것입니다. 간단한 케이스가 당신을 위해 작동하고, 당신은 특정한 윤곽에서만서만 말썽이 있는가? –
필자의 경우 트랜잭션은 주석이있는 조건과 주석이없는 조건 모두에서 롤백되지 않았습니다. – Dipesh