vendredi 20 février 2015

How to get hibernate session within method with @Async annotation

I am using Spring 4.0.5


I want to perform some db operation using @Async method but the data is not getting saved, when I remove the @Async annotation it works fine.


I know the problem is because hibernate session is not available in the new thread. Can any one know the solution for the same, what exactly I need to do.


Here is the code snippet



Controller.java

taskExecutorService.insertLoginDetails(data);


TaskExecutorService.java

@Async
public void insertLoginDetails(LoginDetail data) {
sessionFactory.getCurrentSession().save(data);
}


thanks, -bond


Aucun commentaire:

Enregistrer un commentaire