0
votes

In spring configuration file, my company's last developer declared as

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
        <ref bean="autoCreateHocDS"/>
    </property>
</bean>

but there were no any AOP or annotation like @Transaction written to define on what class its should be applied.

My first execution class here is OCsAutoCreateHocJob and it's internally call Service and dao classes.

So here my doubt is on what level transaction management will applied in class chain OR it will not apply without defining transaction level OR transaction management will applied to all classes?

1

1 Answers

0
votes

You normally annotate your Service layer with @Transaction because this is the layer where you do your business logic (calculations, data manipulations, etc) that requires multiple calls to your DAO layer. This way, you can do a bunch of database methods using a single transaction, wherein you can rollback all database actions made in case something wrong happens.

<!-- proxy-target-class is set to true to use transactional scope -->
    <tx:annotation-driven proxy-target-class="true" transaction-manager="tomcatTransactionManager" />

<!-- Transaction Manager -->
    <bean id="tomcatTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="myDataSource" />
    </bean>