• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

@Async and @Transactional: not working

 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see code.

1. When I called the method @Async loadMarkUpPCT(), data is NOT committed into the table. It behaves as if it's non-tractional.

2. When I removed @Async from loadMarkUpPCT (Class 1), i.e. non-async, then data is committed and OK as expected: transactional)

I was expecting to have the same result with @Async and @Transactional but it's NOT. Please explain or what did I do wrong?

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I too have the same issue.

Is any one provide the solution?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you people configured <task:executor id="myExecutor" pool-size="5"/> in your configuration file?
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have:


With yours:


still NOT working.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there is nothing wrong with your code as you have it.

I did notice this post you had here:
http://stackoverflow.com/questions/19935809/async-and-transactional-not-working

It looks like you are using an OpenEntityManagerInViewFilter. I am not a big fan of this filter and usually recommend against its use, if you have lazy load exceptions handle that by making sure the data is loaded before the transactional method completes if you know you are going to need it. I am fairly certain your problem stems from the use of that filter, I don't think it can be safely taken across thread boundaries. Try removing it. I don't see anything else amiss in what you have posted.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just looking at the API for OpenSessionInViewFilter

http://docs.spring.io/spring/docs/3.2.5.RELEASE/javadoc-api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

I am curious sometime to look at the source and see how they handle the multi threading, as entity managers are not thread safe, and the class appears to me to attach the entity manager to a thread local which it keeps for the duration of the request.

It looks like it should be able to handle this, since it has a shouldNotFilterAsyncDispatch() method, but its still the first thing I would take out to see if it helps, since nothing else stands out to me in your code.

Is markUpPCT a transient object (brand new, never been persisted)? I see you are calling entityManager.persist() which assumes the object is new. It would throw an exception if it was not but if there were an exception you wont see it in the code I am looking at. It might also be a good idea to catch any exceptions and log them, inside the async since you cant throw exceptions out of there.
 
reply
    Bookmark Topic Watch Topic
  • New Topic