Hibernate(十)--spring整合hibernate
结构:

Spring和Hibernate整合借助于HibernateTemplate
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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.lc.pojo.Category">
<property name="name" value="yyy" />
</bean> <bean name="dao" class="com.lc.dao.CategoryDAO">
<property name="sessionFactory" ref="sf" />
</bean> <bean name="sf"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="ds" />
<property name="mappingResources">
<list>
<value>com/lc/pojo/Category.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hbm2ddl.auto=update
</value>
</property>
</bean> <!-- 数据源-->
<bean name="ds"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=GBK" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean> </beans>
测试:
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
CategoryDAO bean =(CategoryDAO) context.getBean("dao");
DetachedCriteria criteria = DetachedCriteria.forClass(Category.class);
// List<Category> list = bean.findByCriteria(criteria, 0, 5); //分页--取0-5个返回
// System.out.println(list);

Category.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.lc.pojo"> <class name="Category" table="category_">
<id name="id" column="id">
<generator class="native">
</generator>
</id>
<property name="name" />
</class> </hibernate-mapping>
result:

Hibernate(十)--spring整合hibernate的更多相关文章
- 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】
一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...
- spring整合hibernate的详细步骤
Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...
- spring整合hibernate
spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...
- spring 整合hibernate
1. Spring 整合 Hibernate 整合什么 ? 1). 有 IOC 容器来管理 Hibernate 的 SessionFactory2). 让 Hibernate 使用上 Spring 的 ...
- Spring 整合 Hibernate
Spring 整合 Hibernate •Spring 支持大多数流行的 ORM 框架, 包括 Hibernate JDO, TopLink, Ibatis 和 JPA. •Spring 对这些 OR ...
- 使用Spring整合Hibernate,并实现对数据表的增、删、改、查的功能
1.1 问题 使用Spring整合Hibernate,并实现资费表的增.删.改.查. 1.2 方案 Spring整合Hibernate的步骤: 1.3 步骤 实现此案例需要按照如下步骤进行. 采用的环 ...
- Spring整合Hibernate详细步骤
阅读目录 一.概述 二.整合步骤 回到顶部 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让Hibernate使 ...
- SSH整合之spring整合hibernate
SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...
- 【Spring】Spring系列6之Spring整合Hibernate
6.Spring整合Hibernate 6.1.准备工作 6.2.示例 com.xcloud.entities.book com.xcloud.dao.book com.xcloud.service. ...
随机推荐
- 第一个Tornado程序
环境:Python3.8 系统:win10 1903 工具:pycharm2019.3 import tornado.web # web服务基本功能都封装在此模块中 import tornado.io ...
- 01初步启动Hadoop服务
1.rz命令将hadoop压缩包上传至Linux服务器中 2.tar -zxvf hadoop-2.7.7.tar.gz(解压即可用) 3.将解压出来的hadoop移到想要放的位置 mv hadoop ...
- ES5中的this
参考资料:>>> this的指向 在 ES5 中,其实 this 的指向,始终坚持一个原理: this 永远指向最后调用它的那个对象 下面我们来看一个最简单的例子:(例子均来自参考资 ...
- Linux创建智能DNS
根据客户端源IP地址的不同,DNS服务提供不同的解析地址 1.安装dns服务,修改全局配置文件/etc/named.conf # yum -y install bind # vim /etc/name ...
- onContextItemSelected 与 onMenuItemSelected 的那些事
Android 的activity中onCreateOptionsMenu onMenuItemSelected onOptionsItemSelected onCreateContextMenu o ...
- 「NOI2005」维护数列
「NOI2005」维护数列 传送门 维护过程有点像线段树. 但我们知道线段树的节点并不是实际节点,而平衡树的节点是实际节点. 所以在向上合并信息时要加入根节点信息. 然后节点再删除后编号要回退(栈), ...
- 搜索栏UISearchBar的使用
本文结构: 1.首先是对UISearchBar的简介文字 2.初始化展现UISearchBar,并解析它的结构 3.属性.方法.代理等的一一介绍 4.日常的使用,包括单独对UISearchBar的配置 ...
- pytorc人工神经网络Logistic regression与全连接层
//2019.10.08神经网络与全连接层1.logistics regression逻辑回归的思想是将数据利用激活函数sigmoid函数转换为0-1的概率,然后定义一定的阈值0.5,大于阈值则为一类 ...
- 三 传递包装pojo&ResultMap
传递包装pojo: 将实体类对象封装在QueryVo类中进行操作 mapper接口: mapper映射文件: 测试: ResultMap的使用: type:映射成的pojo类型 id:resultMa ...
- Android 获取当前日期距离过期时间的日期差值的完整方法直接使用
/*** * 获取当前日期距离过期时间的日期差值 * @param endTime * @return */public String dateDiff(String endTime) { Strin ...