I understand this question has been asked many time, but most can't explain my problem:
@RequestMapping("/testing")
public String testing(HttpServletRequest request, final ModelMap model)
{
Transaction ut = session.openSession().beginTransaction();
session.getCurrentSession(); // error here
ut.commit();
return "testing";
}
Why I am getting the error
Could not obtain transaction-synchronized Session for current thread.
If I annotate the method with @Transactional
, it is working perfectly fine. Because I have @EnableTransactionManagement
in my spring context.
I want to try something to understand the difference between getCurrentSession
and openSession
, so I created test case above.
getCurrentSession
is called within a active Transaction context, why it is still throwing me error???
Refer the code from this.