Sep 16th, 2011, 10:51 AM
Keep Session open for TaskExecutor
I have a Spring Controller that needs to deliver several email notifications as a side effect to persisting a domain entity. The emails are formed and delivered in a background thread via autowired TaskExecutor for a speedy user experience, but the problem is that Spring closes my Hibernate session as soon as the resulting View is finished rendering (while the background task is still using it). Obviously, this is causing lazy initialization exceptions.
Is there a way to keep a Spring-managed Hibernate session open for the duration of background threads launched using TaskExecutor?
Tags for this Thread