org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thre

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





緣由不詳:

解決方法:
一是在web.xml添加:
   
   
   
   
<filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>


還沒那麼深刻了解,對這種方法表示像喝白開水,不感冒。java


仍是方法二好理解點:web


1
2
3
添加:
 
@Transactional(propagation = Propagation.REQUIRED)

不過,記得還要在spring的配置文件上添加spring

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

否則單單添加     @Transactional也沒有用的!!
app


​例如:url





相關文章
相關標籤/搜索