org.hibernate.HibernateException: No CurrentSessionContext configured 错误解决
org.hibernate.HibernateException: No CurrentSessionContext configured 异常解决.
发生异常环境及行为:
项目中使用spring/hibernate框架时,获取对象发生错误:
分析:
需要进行SessionFactory.getCurrentSession()操作,配置文件中需要如下配置:
<prop key="hibernate.current_session_context_class">thread</prop>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>com/yfkj/shop/server/po/TUserInfo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
注:红色字体
-----------工作积累 尹当