Hibernate Open-Session-In-View Pattern

用hibernate,继续写代码来处理关联关系很繁,考虑用关联映射。

一用就是臭名昭著的 LazyInitializationException,于是参考hibernate的best practice使用Open-Session-In-View方式。

 

http://www.jroller.com/cardsharp/entry/open_session_in_view_pattern

 

这篇文章说得实在:在表现层暴露back-end的处理机制总觉得不妥当,但是用起来这么透明、这么简便,那就用着吧 :-)

 

至于性能,网上讨论很多。从理论上分析,是有影响的。但是,影响到多大程度?在超过什么样的压力阈值之后会出现问题?

 

对于企业内部的应用,不超过10,000个用户,应该不至于成为瓶颈。

 

毕竟,现在的应用软件开发对开发速度、代码的可维护性等方面的要求更为挑战。

 

ps:

 

配置中:

org.springframework.orm.hibernate.support.OpenSessionInViewFilter

                                         ~~~~~~~

需要修改为

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

 

遇到几个配置的地方,都会因为少一个3导致 class not found.

 

 

Configuring Open-Session-In-View

Here's a excerpt from a simple web.xml that loads Spring configuration files from the classpath and activates the Open-Session-in-View for a Tapestry application:

 

<web-app>
  <!-- web-app settings go here -->

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:/com/yourcompany/daopackage/applicationContext-hibernate.xml,
      classpath:/com/yourcompany/servicepackage/applicationContext-service.xml
    </param-value>
  </context-param>

  <!-- Spring Open Session In View Pattern filter -->
  <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
      org.springframework.orm.hibernate.support.OpenSessionInViewFilter
    </filter-class>
  </filter>

  <!-- Spring/Hibernate filter mappings -->
  <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/app/*</url-pattern>
  </filter-mapping>

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

  <!-- Servlet mappings & other config -->
</web-app>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值