用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>