You actually need to retrieve the same session that Spring is using by calling:
Session session = sessionFactory.getCurrentSession();
The call to openSession()
will create an entirely new session that is not being managed by Spring, as opposed to the call to getCurrentSession()
, that retrieves the same session managed by the @Transactional
mechanism.