Thursday, July 3, 2008

Spring / Hibernate: No Hibernate Session bound to thread...

I've been working on adding basic persistence to a Spring/CXF web service. The setup is pretty straightforward, and is based closely on the PetClinic sample in the spring distribution. However, once I tried to run a JUnit test to validate a save operation in my persistence DAO, I got this error message:

"No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

The short solution: Make sure that your hibernate properties contain the following:
- hibernate.current_session_context_class = thread
- hibernate.transaction.factory_class = org.hibernate.transaction.JDBCTransactionFactory
I haven't investigated yet what the impact of these changes will be on performance, etc. However, it does resolve this error message.

The details:
- CFX 2.1.1
- JBoss 4.0.5GA
- Hibernate 3.2.6ga
- Sun JDK 1.6_6
- Spring 2.5.4

The context:
* Trying to save an object to a database via a Spring-configured Hibernate session

No comments: