查了一下相关资料,整理以下: java
缘由:Hibernate4 No Session found for current thread缘由 web
解决方法: spring
1. 在spring 配置文件中加入 session

程序代码
<tx:annotation-driven transaction-manager="transactionManager"/>
而且在处理业务逻辑的类上采用注解

程序代码
@Service
public class CustomerServiceImpl implements CustomerService {
@Transactional
public void saveCustomer(Customer customer) {
customerDaoImpl.saveCustomer(customer);
}
...
}
另外在 hibernate 的配置文件中,也能够增长这样的配置来避免这个错误:

程序代码
<property name="current_session_context_class">thread</property>
解决方法二:http://zhidao.baidu.com/link?url=BNyi8By29DMOXBCiNLeTa7WTTxlf4Q4IbQkrYO6lv6MFNMxv5zkBIx723t4JkezOaNcxc9ARhDIeXxtRZbID_0jYKonThVemDs1VkBUFmpK app
我也出现了这个问题,可是我在web.xml中增长了filter就能够了。也许你的问题不是这个,但个人这个问题是这么解决的。
<filter>
<filter-name>SpringOpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SpringOpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>