HibernateException: Could not obtain transaction-synchronized Session for current thread

After i update to spring4/hibernate4. i got above exception.

Turns out that i need to add

<tx:annotation-driven transaction-manager=”transactionManager”/>

and

@Transactional

to my rest controller so that when the service/dao calls getCurrentSession(), spring could start the transaction and opens session from its own transaction management thru AOP.

 

If you encountered this when running unit test, it is possible that you forget to add @Transaction annotation to the Junit test class or method.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s