この質問が何度も出されていることは理解していますが、ほとんどの人は私の問題を説明できません:
@RequestMapping("/testing")
public String testing(HttpServletRequest request, final ModelMap model)
{
Transaction ut = session.openSession().beginTransaction();
session.getCurrentSession(); // error here
ut.commit();
return "testing";
}
エラーが発生する理由
Could not obtain transaction-synchronized Session for current thread.
メソッドに で注釈を付けると@Transactional
、完全に正常に機能します。私は@EnableTransactionManagement
私の春の文脈にあるからです。
getCurrentSession
との違いを理解するために何か試してみたいopenSession
ので、上記のテストケースを作成しました。
getCurrentSession
アクティブなトランザクション コンテキスト内で呼び出されますが、なぜまだエラーが発生するのですか?
コードはこちらから参照してください。