私はWriteTxnFinishProcessorTestを試そうとしましたが、例外なく実行されます。 hibernateログはロールバックを正しく示していますが、dbフィールド 'LastUpdateTime'は新しい値を更新します。 なぜですか? HibernateCallbackは休止状態のトランザクションの下にありませんか?HibernateCallbackを使用したSpringテストは動作しません
次のようにログ表示:
[main ] 20120104 15:44:54.284 INFO HibernateTransactionManager - Using DataSource [com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 5000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 2sa1nt8k1aivnzwna070g|1a7b0bf, debugUnreturnedConnectionStackTraces -> true, description -> null, driverClass -> com.sybase.jdbc3.jdbc.SybDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2sa1nt8k1aivnzwna070g|1a7b0bf, idleConnectionTestPeriod -> 120, initialPoolSize -> 2, jdbcUrl -> jdbc:sybase:Tds:10.10.10.203:6332/NIAIMM, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 180, maxIdleTimeExcessConnections -> 120, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 60, usesTraditionalReflectiveProxies -> false ]] of Hibernate SessionFactory for HibernateTransactionManager
[main ] 20120104 15:44:54.557 DEBUG AbstractPlatformTransactionManager - Creating new transaction with name [testProcessIn]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
[main ] 20120104 15:44:54.614 DEBUG HibernateTransactionManager - Opened new Session [[email protected]] for Hibernate transaction
[main ] 20120104 15:44:54.619 DEBUG HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [[email protected]]
[main ] 20120104 15:44:54.652 DEBUG HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [[email protected]]
[main ] 20120104 15:44:54.668 DEBUG LoggingAspect - DAO:GenericDAOImpl.executeHQLUpdate
[main ] 20120104 15:44:54.680 DEBUG LoggingAspect - args:[update DailyImmigrationsTemp set ImmigRcode='0000', LastUpdateTime=?, TxnMark=0 where EdCardNo=? and Port=? and ImmigrateDate=? and ImmigrateSeq=?, [Ljava.lang.Object;@1267610]
[main ] 20120104 15:44:55.372 DEBUG SQLStatementLogger - update DailyImmigrationsTemp set ImmigRcode='0000', LastUpdateTime=?, TxnMark=0 where EdCardNo=? and Port=? and ImmigrateDate=? and ImmigrateSeq=?
[main ] 20120104 15:44:55.421 WARN LoggingAspect - execution time:740 ms, return:1
[main ] 20120104 15:44:55.422 DEBUG AbstractPlatformTransactionManager - Initiating transaction rollback
[main ] 20120104 15:44:55.422 DEBUG HibernateTransactionManager - Rolling back Hibernate transaction on Session [[email protected]]
[main ] 20120104 15:44:55.455 DEBUG HibernateTransactionManager - Closing Hibernate Session [[email protected]] after transaction
=== WriteTxnFinishProcessorTest.java ===
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContextTest.xml")
@TransactionConfiguration(transactionManager="txManager",defaultRollback=true)
@Transactional
public class WriteTxnFinishProcessorTest {
@Autowired
private GenericDAO dailyImmigrationsTempDAO;
@Test
public void testProcessIn() {
String hql="update DailyImmigrationsTemp set LastUpdateTime=? where EdCardNo=? and Port=? and ImmigrateDate=? and ImmigrateSeq=?";
Object[] params=new Object[]{new Date(),"5550137001",12,"20111214",1};
int cnt = dailyImmigrationsTempDAO.executeHQLUpdate(hql, params);
System.out.println("cnt:"+cnt);
}
}
=== DailyImmigrationsTempDAO.java ===
:
:
public int executeHQLUpdate(final String hql, final Object[] params){
int ret = (Integer)getHibernateTemplate().execute(new HibernateCallback<Object>() {
public Object doInHibernate(Session sess) throws HibernateException {
Query query = sess.createQuery(hql);
for (int i=0;i<params.length;i++){
query.setParameter(i, params[i]);
}
return query.executeUpdate();
}
});
return ret;
}
= == applicationContextTest.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
:
:
</bean>
<bean id="abstractDAO" abstract="true">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" destroy-method="destroy">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="packagesToScan">
<list>
<value>com.pojo</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="dailyImmigrationsTempDAO" class="com.dao.GenericDAOImpl" parent="abstractDAO">
<constructor-arg value="com.pojo.DailyImmigrationsTemp" />
</bean>
</beans>
DailyImmigrationsTempDAOクラスまたはexecuteHQLUpdateメソッドは、Transactiontalアノテーションを持っていますか? – svaor