私は、JSF、Spring、および Hibernate フレームワークを持つアプリケーションに取り組んでいます。次の方法を使用して、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"/>
誰が私が間違っているのか教えてもらえますか?