Announcement Announcement Module
No announcement yet.
@Async and @Transactional not committing transaction Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Async and @Transactional not committing transaction

    I'm trying to fire off an Async process to do an insert into the database

    I have a component with a method annotated with the @Async annotation that fires off asynchronously. that works fine on its own.
    If I add the @Transactional annotation and make a database insert the commit is not being done. However same method with just the @Transactional annotation works fine. The record gets inserted into the database just find.

    My applicationContext.xml has the

    <tx:annotation-driven transaction-manager="transactionManager" /> and <task:annotation-driven/>

    is there a step I'm missing to connect the 2 and make a method be Async and have a Transaction to go with it?


  • #2
    For each request (if it is from HTTP), it creates separate thread (say thread-id-100) and transactionManager will create Connection object and binds it to the same thread (thread-id-100) that is created by the request. Inside the @Transactional method, it uses the same Connection object that is created by the transactional Aspect and will be used for all DAO operation to make it unit-of-work. Hence it works fine.

    @Async annotation will create another separate thread (say, thread-id-201) from thread-id-100 and the new thread will not have an access to the Connection object that is created by thread-id-100. Hence the behavior.