星空网 > 软件开发 > Java

spring openSessionInView 基础配置


WebRoot/WEB-INF/web.

<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><filter><filter-name>openSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class><init-param><param-name>sessionFactoryBeanName</param-name><param-value>sessionFactory</param-value></init-param><init-param><param-name>singleSession</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>openSessionInViewFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>

 

 


注意放在struts前,如果项目有启用的话

DAO层调用session时使用 getCurrentSession() ,而不是openSession() 且搭配事务使用,手动开启和提交事务, 

如果之后需要使用到级联,则不应该关闭session;

注意除了查询操作以外,都应该调用session.flush()方法,以确保对数据库的写入.

 

主要遇到的问题就是session的关闭,之前以为使用了opensessioninview是关闭也没关系的.这点在找到的资料里也没有说明,所以才被误导了

目前只知道基本的使用而已,只是为了解决Lazy Load的级联问题, 对于这个功能还需要进一步了解.

 




原标题:spring openSessionInView 基础配置

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

tiktok东南亚市场:https://www.goluckyvip.com/tag/82381.html
tiktok·com:https://www.goluckyvip.com/tag/82382.html
tiktok分享:https://www.goluckyvip.com/tag/82383.html
tiktok店铺登录:https://www.goluckyvip.com/tag/82384.html
tiktok法国:https://www.goluckyvip.com/tag/82385.html
tiktok联系电话:https://www.goluckyvip.com/tag/82386.html
太仓美食网(探寻太仓最美味的美食):https://www.vstour.cn/a/406244.html
莫干山门票多少?:https://www.vstour.cn/a/407226.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流