• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring + Hibernate No Session found for current thread

 
Sergej Smoljanov
Ranch Hand
Posts: 468
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java based spring mvc configuration

Dispatcher


Web config. ViewResolver bean


RootConfig. Bean for DataSource , LocalSessionFactoryBean , BeanPostProcessor

Interface for persistence logic

How i try use hibernate to save object

Controller:

Object that i want for save:

View
JSP where i place form for saving object


finally when i try save object i get:
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/Spring_Demo_Aplication] threw exception [Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateSystemException: No Session found for current thread; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root cause
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1013)
at com.myspringapp.config.persistance.HebernatePersist.saveObject(HebernatePersist.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)


And cant figure where error i made. How can i solve this problem?
 
Sergej Smoljanov
Ranch Hand
Posts: 468
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My solution was
add
@EnableTransactionManagement to class RootConfig
also add next bean to this class


also i change HibernatePersist this way and this will work for me

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic