Problème transaction rollback requête alter table
Bonjour,
Le rollback d'une requête alter table ne fonctionne pas pour le code suivant, par contre le rollback des requêtes insert fonctionne. J'utilise une base de données HSQLDB.
this my service class :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class DataBaseMigrationService extends HibernateDaoSupport implements
IDataBaseMigrationService {
public void runDataBaseMigration() {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
// Check if the column I want to add exists or not
SQLQuery selectQuery = session
.createSQLQuery("SELECT COLUMN_NAME FROM \"INFORMATION_SCHEMA\".\"SYSTEM_COLUMNS\" where "
+ "TABLE_NAME = 'IO_MODULES' and COLUMN_NAME = 'CH_ADDR_GENERATORS'");
Object uniqueResult = selectQuery.uniqueResult();
if (uniqueResult == null) {
SQLQuery updateQuery = session
.createSQLQuery("alter table IO_MODULES add COLUMN CH_ADDR_GENERATORS varbinary(255)");
updateQuery.executeUpdate();
// this call will insert data in the new created column
setChannelsAdressGenerator4AllModules();
}
return uniqueResult;
}
});
}
private void setChannelsAdressGenerator4AllModules() {
// this method make inserts in database and use HibernateTemplate
......
// an error occurs here, and logically the alter table query in the previous code must be rollbacked
}
} |
The interface of my service :
Code:
1 2 3 4 5 6
| package com.rockwellautomation.neat.v5.connector.services.interfaces;
public interface IDataBaseMigrationService {
public void runDataBaseMigration();
} |
Declratif transaction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="factory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="run*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="txServiceOperation" expression="execution(* com.rockwellautomation.neat.v5.connector.services.interfaces.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txServiceOperation"/>
</aop:config> |
Merci pour votra précieuse aide.