用ssh整合时,用sessionfactory的getCurrentSession()获取不到session

在用ssh整合时,一开始用的是getCurrentSession(),获取当前线程上的session,但是总是抛异常,不能获取。

后来用sessionfactory的openSession(),但是,会发现一旦程序多次运行就会报错,提示没得session可获取。

那么怎么解决呢。

在beans.xml里面的hibernateProperties配置hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext,class可根据自己实际运用的包而定。并且在service里面加上事务注解@Transactional。问题就能解决了。

时间: 2024-08-29 05:12:24

用ssh整合时,用sessionfactory的getCurrentSession()获取不到session的相关文章

ssh整合案例出了could not initialize proxy - no Session 问题,那个大神帮我看看

在做SSH项目时,控制台出现这个错误,请大神帮忙看看啊2017-04-14 11:15:57,902 DEBUG (org.springframework.beans.factory.support.DefaultListableBeanFactory:1140) - Added autowiring by name from bean name 'cn.bdqn.jboa.action.EmployeeAction' via property 'employeeBiz' to bean nam

SSH整合时,关于访问数据库的load的错误

1 当web.xml中没有配置以下拦截时,会出现 <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactor

SSH整合时jar包冲突解决的注意事项

在SSH项目整合的时候,要注意jar包冲突. 这里的原则是: 1,无依赖关系的舍低取高. 2.有依赖关系的取高. 怎么排查是否有冲突,在服务器项目的lib下查看是否有重名的. 注意:每次重新导入包以后要把服务器中的项目删掉再发布.

在myeclipse中maven项目关于ssh整合时通过pom.xml导入依赖是pom.xml头部会报错

错误如下 ArtifactTransferException: Failure to transfer org.springframework:spring-jdbc:jar:3.0.5.RELEASE from http:// repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of  central has

ssh整合之五struts和spring整合

1.首先,我们需要先分析一下,我们的spring容器在web环境中,只需要一份就可以了 另外,就是我们的spring容器,要在我们tomcat启动的时候就创建好了(包括其中的spring的对象),怎么保证我们的spring容器能创建呢? 我们可以配合监听器来创建我们的spring容器,然后我们怎么实现我们的监听器呢? 当ServletContext创建成功,就说明tomcat正常启动了,我们使用监听器监听我们的ServletContext,如果创建成功,加载配置文件,创建spring容器 2.我

ssh整合之三hibernate和spring整合

1.拷贝我们的spring事务控制所需的jar包 2.在spring容器中配置我们的hibernateTemplate以及事务管理器 <?xml version="1.0" encoding="UTF-8"?> <!-- spring的配置文件:导入约束 --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="htt

SSH整合开发时Scope为默认时现象与原理

1.前提知识 1)scope默认值 进行SSH整合开发时,Struts2的action需要用spring容器进行管理,只要涉及到类以bean的形式入到spring容器中,不管是xml配置还是使用注解方式进行配置,都会涉及到spring管理bean的scope,其一共有五种取值,而其默认值为singleton,也就是单例模型,所有对此bean引用为同一个对象. 2)action应为多例 struts2作为MVC中视图(View)层框架,其最主要任务就是接收用户请求,然后调用业务逻辑层进行处理,这种

在使用SessionFactory的getCurrentSession方法时遇到如下错误

遇到过的问题: 情景1: 在使用SessionFactory的getCurrentSession方法时遇到如下错误,经过检查,原因如下: 是因为在hibernate.cfg.xml文件中忘记进行了如下设置: hibernate.current_session_context_class如果是在web容器中运行hibernate,则在hibernate.cfg.xml中加入这句话: <property name="hibernate.current_session_context_class

从MVC和三层架构说到SSH整合开发

相信很多人都认同JavaWeb开发是遵从MVC开发模式的,遵从三层架构进行开发的,是的,大家都这么认同.但是相信大家都会有过这样一个疑问,if(MVC三层模式==三层架构思想)out.println(“请继续观看……”) 1.MVC(MODEL-VIEW-CONTROLLER)设计模式: 首先让我们了解下MVC(Model-View-Controller)的概念: MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写