The currentSession
turns out in many situations to be very fragile.
You may have undefined state after an error, so please make sure that your "current session" and transaction was not destroyed by a previous error. to achive this, print out the transaction state (isActive
) just before using calling getCurrentSession
inside the DAO.
Double-check that the SessionContext
is configured and working; call getCurrentSession
twice and check if returned instances are same, if not, you may are looking at different sessions:
assert getCurrentSession()==getCurrentSession()
I learned hard lessons to be very conservative with Hibernate. So spending some time on basics really pays off.