开发者社区> 问答> 正文

Spring3.2整合hibernate4.2报错:No Session fou?报错

我本来用的hibernate3的+spring3.2,我现在将hibernate3升级到hibernate4.2后,总报这个错:

2014-08-17 13:04:10,132 ERROR (UserDaoImpl.java:41) - login
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:993)
at com.back.dao.impl.UserDaoImpl.login(UserDaoImpl.java:33)

请各位高手帮我看看到底是什么问题?感谢!!!
我的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">


<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.back.dao.impl"></context:component-scan>
<context:component-scan base-package="com.back.service.impl"></context:component-scan>
<context:component-scan base-package="com.back.action"></context:component-scan>
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.gjt.mm.mysql.Driver" />
<property name="jdbcUrl"
value="jdbc:mysql://127.0.0.1:3306/push?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="gjs@y1" />
<!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 chengkai@fee -->
<property name="initialPoolSize" value="1" />
<!-- 连接池中保留的最小连接数。 -->
<property name="minPoolSize" value="1" />
<!-- 连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="300" />
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="60" />
<!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="5" />
<!-- 每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod" value="60" />
</bean>
<!-- 数据源 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/back/entity/User.hbm.xml</value>
<value>com/back/entity/Project.hbm.xml</value>
<value>com/back/entity/Product.hbm.xml</value>
<value>com/back/entity/Item.hbm.xml</value>
<value>com/back/entity/Machine.hbm.xml</value>
<value>com/back/entity/Integrate.hbm.xml</value>
<value>com/back/entity/Apk.hbm.xml</value>
<value>com/back/entity/Apkactive.hbm.xml</value>
<value>com/back/entity/Department.hbm.xml</value>
<value>com/back/entity/Channel.hbm.xml</value>
<value>com/back/entity/Pactive.hbm.xml</value>
<value>com/back/entity/Pinstall.hbm.xml</value>
<value>com/back/entity/Linkads.hbm.xml</value>
<value>com/back/entity/Linklog.hbm.xml</value>
<value>com/back/entity/Smsads.hbm.xml</value>
<value>com/back/entity/Smslog.hbm.xml</value>
<value>com/back/entity/BindLink.hbm.xml</value>
<value>com/back/entity/Statis.hbm.xml</value>
<value>com/back/entity/BindSms.hbm.xml</value>
</list>
</property>
<!-- hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -->
<property name="hibernateProperties">
<props>
<prop key="current_session_context_class">thread</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="format_sql">true</prop>
<prop key="show_sql">false</prop>
</props>
</property>
</bean>
<bean id="SpringContextUtil" class="com.back.util.SpringContextUtil" />
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 使用基于注解方式配置事务 -->
<tx:annotation-driven transaction-manager="txManager" />
</beans>

展开
收起
爱吃鱼的程序员 2020-06-14 22:41:52 482 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    将如下这行去掉即可(去掉就是默认的Propagation.REQUIRED):
    @Transactional(propagation=Propagation.NOT_SUPPORTED)

    上次我也遇到。好像4.2以后把什么东西去掉了,忘了,我直接换成3.6了

    引用来自“高金山”的评论

    将如下这行去掉即可(去掉就是默认的Propagation.REQUIRED):
    @Transactional(propagation=Propagation.NOT_SUPPORTED)

    没有开opensessioninview

    你没配置事务~ 

    spring来管理hibernate的话 如果不声明事务的管理方式的话

    openSession的话会报错~

    2020-06-14 22:42:08
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多