我有一个抽象类和两个子类来扩展它。我在Spring配置文件spring @Transactional注释
<bean id="importConfigFile" class="xxx.ImportConfigFiles" parent="parentImportFile"></bean>
<bean id="importFile" class="xxx.ImportUMTSKPIFiles" parent="parentImportFile"></bean>
<bean id="parentImportFile" name="parentImportFile" class="xxx.ImportUMTSFiles" abstract="true"></bean>
<tx:annotation-driven transaction-manager="transactionManager" />
以下在我的抽象类,我有以下方法
public void importDataToDB(){
//all the good stuff goes in here
}
@Transactional
public void executeInsertUpdateQuery(){
//all the good stuff goes in here
}
我的Java代码
ImportConfigFiles importConfigFiles = (ImportConfigFiles)context.getBean("importConfigFile");
importConfigFiles.setFileLocation(destPath);
importConfigFiles.importDataToDB();
这是行不通的。 executeInsertUpdateQuery()只执行一个本地sql查询。如果我将@Transactional放在imortDataToDB()上,它可以工作,但是这会使我的事务变得很大,因为在该方法中,我循环遍历文件中的所有行并将记录插入到db中。
感谢您的快速响应。 – user373201