Spring annotation @Transactional

I have an abstract class and two subclasses that extend it. I have the following spring configuration file

<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" />

In my abstract class, I have the following methods

public void importDataToDB(){
    //all the good stuff goes in here
}

@Transactional
public void executeInsertUpdateQuery(){
    //all the good stuff goes in here
}

My java code

ImportConfigFiles importConfigFiles = (ImportConfigFiles)context.getBean("importConfigFile");
importConfigFiles.setFileLocation(destPath);
importConfigFiles.importDataToDB();

This does not work. executeInsertUpdateQuery () executes only one native SQL query. If I put @Transactional on imortDataToDB (), it works, but then it makes my transaction huge, because inside this method I look through all the lines in the file and insert the records in db.

+5
source share
2 answers

Spring - @Transactional - , @Transactional ( AspectJ ). Spring - EJB .

, - :

public class BeanA() {

    @Resource
    private BeanB b;

    public void importDataToDB(){
        b.executeInsertUpdateQuery();
    }
}

public class BeanB {

    @Transactional
    public void executeInsertUpdateQuery(){
        //all the good stuff goes in here
    }

}

- AOP Spring. , b.executeInsertUpdateQuery() BeanA.

Spring : , Spring AOP riddle Spring AOP riddle demystified.

+8

, , @Transactional , , , , . , - , , .

, @Transactional , , , , , 10 , .

0

All Articles