I meet a problem,When I use hibernate without Spring,I always write follow configuration in hibernate.cfg.xml:
<property name="current_session_context_class">thread</property>
this bind the seesion to thread.But When I use hibernate togther with Spring,I don't know how to implement same configuration,I also write it in applicationContext.xml,but it doesn't work. throw exception:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Actually I just want to bind session to thread,then I can use sessionfactory's getcurrentSession method,Did someone meet the same problem as me,how to solve it.Thanks a lot
Try adding a @Transactional
annotation on your method which use the hibernate session.
It seems that your methods need transaction.
There are lots of way to configure to use transaction in Spring.
Below is the one of them.
Just a snippet so you should use this code in your way.
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
See SpringMVC 3.2 hibernate docs for more information.