Announcement Announcement Module
No announcement yet.
@Transactional doesnt create a transaction Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Transactional doesnt create a transaction


    i have a weird issue here. I am using this spring config:

    <tx:annotation-driven transaction-manager="txManager"/>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="dataSource"/>


    pretty straighforward i think. Now the following caller scenario:

    public class A implements AIF {

    public void starter() {

    public void methodA() {
    throw new RuntimeException("error");


    public class B implements BIF {
    @Transactional(propagation = Propagation.Mandatory)
    public void updateDB() {

    Of course, both classes are managed by Spring. Now when i run this scenario, i am getting a SpringException upon entering updateDB() method because Spring says that there is no existing transaction. Weird. When i remove Mandatory Propagation, i am getting to MY RuntimeException, but since there is no Transaction on this method, updateDB() doesnt rollback.

    Now the big question: Why does Spring not put A.methodA() under transactional control? In fact in the logs i dont see any "Creating new Transaction...." in the Method A block, only in UpdateDB(). But as you all can see, i have a Transactional Attribute on MethodA().

    I am trying for hours now and cant see the problem.... thanks for advice.


  • #2
    replying to myself....

    Calling a Transactional method inside a class is the issue because Spring cant intercept such calls as it seems. At least thats what suspect regarding my issue.



    • #3
      If I would get a euro each time I answer this question, I would be rich.

      Read chapter 6.6.1 of the reference guide. Only calls INTO (i.e. external method calls) are intercepted, internal method calls aren't intercepted.


      • #4
        I am thinking of similar situation but with spring's transaction management driven by AspectJ aspects (see 6.8.2). I am not sure but I think that in this case your code would work. Am I right? (will check it in a free time)