解决No Hibernate Session bound to thread, and configuration does not allow creat。。。
applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/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"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="com.donghua"></context:component-scan>
<!-- 加载外部的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 事物管理,配置数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- Connection properties -->
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<!-- Pool properties-->
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="10" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
</bean>
<!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--
<property name="mappingResources">
<list>
<value>com/donghua/bean/Article.hbm.xml</value>
<value>com/donghua/bean/BlogInfo.hbm.xml</value>
<value>com/donghua/bean/ClickNum.hbm.xml</value>
<value>com/donghua/bean/Critique.hbm.xml</value>
<value>com/donghua/bean/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>-->
<!-- 剩余的配置到。cfg.xml中找 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置声明式事物管理器 -->
<bean id="transctionManger"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- (基于注解的方式) -->
<tx:annotation-driven transaction-manager="transctionManger" />
</beans>
dao配置:注解配置
@Service
public class Dao {
@Resource
private SessionFactory sessionfactory;
@Transactional
public void addUser(User user){
Session session = sessionfactory.getCurrentSession();
session.save(user);
}
}
测试
public class BlogTest {
private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
@Test
public void testUser(){
User user = new User("赵六","sdfs","asf","fdd","dd");
Dao dao = (Dao) ac.getBean("dao");
dao.addUser(user);
}
}
解决No Hibernate Session bound to thread, and configuration does not allow creat。。。的更多相关文章
- No Hibernate Session bound to thread, and configuration does not allow creat
No Hibernate Session bound to thread, and configuration does not allow creat 今天遇到这么一个错误,在网上差了很多都没有能解 ...
- spring事务管理出错。No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a ...
- spring 管理事务配置时,结果 报错: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here这个异常
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not al ...
- Hibernate中解决No Hibernate Session bound to thread问题
引用:忘了 首先是getCurrentSession()与openSession()的区别: 1.getCurrentSession()与openSession()的区别? * 采用getCurren ...
- 报错解决:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
大概分析一般使用了注解才会报这方面的错 1.没有在spring的ApplicationContext.xml中开启注解事务 <!-- 开启注解事务 --> <tx:annotatio ...
- 出现No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here异常
问题描述: public void save(BaseEntity baseEntity) { Session session = null; try { session = currentSessi ...
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
如果出现了这个错误,看看在使用Hibernate的时候有没有在事务的环境下执行操作!
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not
遇到这个问题之前,我去百度和谷歌去搜索了一下.发现各种说法.可是针对我的项目而言,也就是公司的项目而言,这个问题的根源并不是是网上所说的那样. 最后是通过自己的想法做測试得到了解决. 1.首先说说我的 ...
随机推荐
- DbConnectionFactory 数据库连接
/** * */package com.sprucetec.dbatch.tmsfee;import java.io.Serializable;import java.sql.Connection;i ...
- 你是否决绝平庸,你有勇气来学C/C++吗,有勇气来检验你是否经得起世界五百强的面试
如果你来传智播客学习 你的目标就是要积累工作经验 有机会参加世界五百强的面试 秒杀世界五百强的面试 赢得高薪的offer! C/C++课程大纲 C语言3周21天 完全掌握C语言的本质,成为一名合 ...
- Strange Towers of Hanoi
题目链接:http://sfxb.openjudge.cn/dongtaiguihua/E/ 题目描述:4个柱子的汉诺塔,求盘子个数n从1到12时,从A移到D所需的最大次数.限制条件和三个柱子的汉诺塔 ...
- nginx File not found 错误分析与解决方法
使用php-fpm解析PHP,出错提示如下:"No input file specified","File not found",原因是php-fpm进程找不到 ...
- c++ 回调类成员函数实现
实现类成员函数的回调,并非静态函数:区分之 #ifndef __CALLBACK_PROXY_H_ #define __CALLBACK_PROXY_H_ template <typename ...
- 从一句SQL得出的启示
select count(*) + 1 from `table` where rank > (select rank from `table` where id = *) 上面那句SQL 给了我 ...
- Windows 10 : 使用BCDboot恢复双系统启动
电脑装上win10以后,立马把原来系统的启动信息删了.结果有个软件需要反激活,但是Win10已经没有Boot.ini这样的启动配置文件. 花了好多时间查找,发现这篇文章.实际操作倒是很简单.执行以下命 ...
- js判断年龄是否在0-100之间
//判断年龄 $('#info_age').change(function(){ var _val = $(this).val(); -]+$/.test( _val ))||_val< || ...
- Linux学习之输入输出重定向
转自:http://www.cnblogs.com/chengmo/archive/2010/10/20/1855805.html 多谢分享 在了解重定向之前,我们先来看看linux 的文件描述符. ...
- 模块化定义JS,让统一文件夹内相同的变量不冲突
两种方法: 1.(function(){……编写代码……})() //先声明一个函数,声明完后直接调用 2.!function(){……编写代码……}()