|
这个主题共有 15 回复 / 2 页 [
1 2
下一页
]
|
|
|
|
|
|
请教open session in view
|
发表: 2005年08月30日 16:37
|
回复
|
|
刚刚接触Spring,我想做个练习,但总出错; struts1.1 + Hibernate3+spring1.2.1+Tomcat5 我想使用open session in view模式 hibernate中以设置成lazy="true"。 抱错:session 以关闭 配置如下
web.xml ?xml version="1.0" encoding="UTF-8"? !DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" web-app display-name wish /display-name context-param param-name contextConfigLocation /param-name param-value /WEB-INF/applicationContext.xml /param-value /context-param filter filter-name HibernateFilter /filter-name filter-class org.springframework.orm.hibernate3.support.OpenSessionInViewFilter /filter-class init-param param-name singleSession /param-name param-value false /param-value /init-param /filter filter-mapping filter-name HibernateFilter /filter-name url-pattern *.do /url-pattern /filter-mapping listener listener-class org.springframework.web.context.ContextLoaderListener /listener-class /listener servlet servlet-name action /servlet-name servlet-class org.apache.struts.action.ActionServlet /servlet-class init-param param-name config /param-name param-value /WEB-INF/struts-config.xml /param-value /init-param init-param param-name debug /param-name param-value 2 /param-value /init-param init-param param-name application /param-name param-value ApplicationResources /param-value /init-param load-on-startup 2 /load-on-startup /servlet servlet-mapping servlet-name action /servlet-name url-pattern *.do /url-pattern /servlet-mapping ......................... ........................... /web-app
struts-config.xml如下 ?xml version="1.0" encoding="UTF-8"? !DOCTYPE Struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" Struts-config form-beans form-bean name="lazyForm" type="sixhero.actionForm.LazyForm" / /form-beans action-mappings action name="lazyForm" path="/test/lazyAction" scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" forward name="ok" path="/test/ok.jsp" / forward name="no" path="/test/no.jsp" / /action /action-mappings message-resources parameter="ApplicationResources" / plug-in className="org.springframework.web.struts.ContextLoaderPlugIn" set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" / /plug-in
/struts-config
ok.jsp如下
%@ page contentType="text/html; charset=GB2312" % %@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" % %@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" % %@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" % %@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" % %@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" % %@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" % html head title ok /title /head body bgcolor="#ffffff"
logic:notEmpty name="list" logic:iterate id="temp" name="list" bean:write name="temp" property="UserName"/ br bean:write name="temp" property="forumDescript"/ br
br bean:write name="temp" property="Order.name" filter="true"/ br br
/logic:iterate
/logic:notEmpty /body /html
Order.name总是抱错
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年08月30日 17:29
|
回复
|
|
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:33
|
回复
|
|
谢谢您的回答:我试了.我哪个关连字段是Order
struts能不能用open session in view,是不是只有用Spring mvc才能用.struts中应该怎么用?或哪里有相关的例子.
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:49
|
回复
|
|
open session in view是你必须做一种过滤器,一直保持Hibernate的session打开,这和Spring有什么关系?Spring是个可有可无的东西,只不过它开发很多方便的API。
在Struts中,Jsp中的order的意思不是你的关联字段,而是相应的getOrder方法,将get去除,O变成小写,所以无论你的字段是大小写,反正Jsp中order是小写,试试一下就知道了。
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:52
|
回复
|
|
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 这个类是否就是Filter,直接用可不可以。
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:55
|
回复
|
|
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:58
|
回复
|
|
|
亏得Gavin King想得出来,还把它上升为模式,自说自话妄图铁板钉钉,这种模式实际是反模式的。不多谈...
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 10:59
|
回复
|
|
|
我知道是po与vo的问题,网上也有类似的讨论。我只是现做一做,看能不能实现。
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 11:06
|
回复
|
|
您能告诉我Struts+hibernate+spring中可不可以实现,若可以我会试着做。但今后不会采用该方法解决问题。 很高兴与您讨论问题。
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 11:13
|
回复
|
|
任何稀奇古怪的方案都是可以实现的。 我觉得你的问题有些主次不分,open session in view是Hibernate为掩饰自己的设计缺点而提出的一个修补方案,它怎么能成为一个整体架构追求实现的目标呢?
Struts等MVC模式框架都是透明的,基于Jsp/Web技术,只要符合J2EE标准的技术有什么不可以实现的呢?
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2005年09月01日 11:25
|
回复
|
|
明白了 open session in view 只是Hibernate为在view层打开的一种连接的实现.与strus无关. 这个问题不占您的时间了. end
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2006年10月14日 14:01
|
回复
|
|
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2006年11月30日 19:34
|
回复
|
|
open session in view 不是一直保持Hibernate的session打开,而是保持它在一个request/response cycle中打开,比较常见的应用情况是在编辑页面点击保存按钮后,先执行一个保存的SERVLET,后通过FORWORD显示保存后的信息。利用过滤器让显示的内容全部读入内存后再COMMIT这个TRANSACTION,这样就可以避免在JSP里面读到某个对象的LAZY LOADING的关联对象时候出现LazyInitializationException: Session has been closed 之类的信息。 GAVIN 绝不会傻到将CONNECTION一直打开的地步。 而Spring里提供了较简便的方法来实现这个PATTERN. 当然不用Spring也可以实现啦 这当然是一个模式,在某些情况下很有用。虽然不是在所有情况下都适合。但每个模式都有其适合和不适合的地方吧。 banq 连自己都不清楚就来说有点太不厚道了吧
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2006年12月06日 12:04
|
回复
|
|
>open session in view 不是一直保持Hibernate的session打开 这个问题已经在其他帖子校正,这个session不是httpSession的意思,而是request生命周期,在这个周期中一直打开着,因为一个request周期中,经过表现层 业务层 持久层三个环节,层层环节相套,Exception等抛出出现之后,处理更加复杂。
|
|
|
|
|
|
Re: 请教open session in view
|
发表: 2006年12月06日 19:23
|
回复
|
|
|
对不起,那是我误解您的意思了,我只是觉得您这么说GAVIN有点不太公平,HIBERNATE还是很不错的
|
|
|
|
|
|
这个主题有 15 回复 / 2 页 [
1 2
下一页
]
|
|
|