openSessionInView实现和LOCK

时间:2012-05-15 16:55:25

标签: spring hibernate locking

我正在尝试使用Spring 2.5.5 Flex / J2EE和Hibernate 3.1.3开发应用程序。 我的问题是,当用户打开“客户信息”屏幕,然后在更改模式下显示客户端的信息时,我希望记录被锁定(悲观或乐观锁定)。注册保持锁定状态,直到用户验证更改(commit())或关闭屏幕。

他们在网上谈论长谈话(Hibernate)和openSessionInView模式。但我没有找到一个明确的例子。

解决方案是让Hibernate会话保持打开状态直到输入结束。 然后进行提交或回滚。

我尝试使用类:“org.springframework.orm.hibernate3.support.OpenSe ssionInViewInterceptor”但我没有成功。 我不知道如何使用Spring配置它。

我花了太多时间而且变得紧急......谁能帮助我?

提前谢谢。

1 个答案:

答案 0 :(得分:0)

必须在web.xml中配置OpenSessionInViewInterceptor

以下示例:

    <filter>
        <filter-name>openSessionInViewFilter</filter-name>
        <filter-class>
           org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        </filter-class>
        <init-param>
             <param-name>sessionFactoryBeanName</param-name>
             <param-value>sessionFactory</param-value> <!-- This is the default value, in case you have given different name please specify the same. -->
        </init-param>            
    </filter>

同时检查documentation是否存在细微问题。

相关问题