spring3+hibernate4出错解决方法如下:在web.xml添加如下配置即可
<!-- openSessionInView配置 -->
<filter><filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
如果用Junit测试的时候总是报No Session found for current thread,这个错误则把
<!-- 拦截器方式配置事物设置为开启事务 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="upd*" propagation="REQUIRED" />
<!--请注意这里 propagation="SUPPORTS" 改为REQUIRED read-only="true" -->
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="load*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="upd*" propagation="REQUIRED" />
<!--请注意这里 propagation="SUPPORTS" 改为REQUIRED read-only="true" -->
<tx:method name="get*" propagation="REQUIRED"
read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED"
read-only="true" />
<tx:method name="search*" propagation="REQUIRED"
read-only="true" />
</tx:attributes>
</tx:advice>