liujianche11 2010-08-17 16:00
浏览 229
已采纳

SSH中hibernate延迟关闭session问题

spring中延迟关闭Session我在web.xml配置了
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- 加载Struts2控制器 -->

FilterDispatcher
org.apache.struts2.dispatcher.FilterDispatcher

<filter-mapping>
    <filter-name>FilterDispatcher</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 将Hibernate的Session生命延长,为了解决由于Hibernate延迟加载,Session过早关闭问题 -->
<filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

<!-- 加载Spring容器 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


index.jsp


然后 tomcat服务器就启动报错报下面的错
严重: Exception starting filter OpenSessionInViewFilter
java.lang.NoSuchFieldError: MANUAL
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.(OpenSessionInViewFilter.java:102)

望各位大哥大姐帮忙

  • 写回答

7条回答 默认 最新

  • oyj7454103 2010-08-17 16:34
    关注

    [color=red]import org.hibernate.*;[/color]
    import org.springframework.web.context.WebApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;
    import org.springframework.web.filter.OncePerRequestFilter;

    public class OpenSessionInViewFilter extends OncePerRequestFilter
    {

    public OpenSessionInViewFilter()
    {
        sessionFactoryBeanName = "sessionFactory";
        singleSession = true;
        [color=red]flushMode = FlushMode.MANUAL;[/color]    }
    

    我看了下 spring 源码! 找到了这个变量! 是hibernate的!

    所以把你的hibernate 的包换一下绝对OK!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler