博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hibernate简单介绍
阅读量:3908 次
发布时间:2019-05-23

本文共 3834 字,大约阅读时间需要 12 分钟。

一: 框架:

集合框架:
DBUtils: 轻量级的框架, 对JDBC 的封装:
1: 框架:定义:
项目的半成品,很多通用型的, 重复型的操作, 封装完成, 直接使用。

2: 作用: 提高开发效率的

二: EE 的三层架构:

在这里插入图片描述
在这里插入图片描述
ibaties是原来的mybatis
mvc三层重命名的话,又可以叫做:表现层,业务层,持久化层:
在这里插入图片描述
三: Hibernate:
1: 什么是Hibernate:
Hibernate 是JDBC重量级封装的ORM框架

面试问题:

2: ORM : Object Relation Mapping 对象关系映射:

Student: 表:

jdbc:
(1)注册驱动,
(2)获得链接:
(3)获得sql 容器
(4)执行语句:
(5)结果集遍历:
映射关系: 通过xml 文件:
create table student(------------------------》 POJO(实体类)

id  int  primary key ,  -----------------> 实体的属性:     sname varchar )Hibernamte 操作: 直接对对象进行操作。 从面相对象的角度出发。

3: Hibernate优点: (简单介绍,面试问题–到时候再百度一下)

(1)减少了代码的重复, 开发效率高。
(2)优秀的ORM框架。
(3)支持各种关系型数据库, 扩展性强。
针对不同数据库,可以生成不同数据库的sql语句。
mybaties比较灵活 ,但是映射关系不强。弊端就是要根据不同的数据库去再实现一套。

二: 环境的搭建:(myeclipse高版本自带hibernate)

1: 下载: 3 4 5 (向下兼容)版本的,4不太好用较为复杂。
2: 解压:
documention : 文档:
lib: Hibernate运行时候的jar 包: 必须的, 可选择的。 根据实际的需求, 定义。
project: 提供了一些使用案例:

3: 使用Hibernate 完成一个最简单的开发:

开发步骤:   (1)创建一个工程: 普通的java 工程就可以。   (2)导入jar包:   (3)创建底层数据库表: 直接导入sql 语句。

在这里插入图片描述

(4)创建实体类: pojo

package com.yidongxueyuan.domain;import java.io.Serializable;/* * 创建了一个普通的实体类:  *  */public class Customer implements Serializable{	private long  cust_id;//客户编号 主键: 	private String cust_name;// 客户名称(公司名称)	private String cust_source;//客户信息来源'	private String cust_industry;//'客户所属行业'	private String cust_level;//客户级别	private String cust_phone;//固定电话',	private String cust_mobile;//移动电话	public long getCust_id() {		return cust_id;	}	public void setCust_id(long cust_id) {		this.cust_id = cust_id;	}	public String getCust_name() {		return cust_name;	}	public void setCust_name(String cust_name) {		this.cust_name = cust_name;	}	public String getCust_source() {		return cust_source;	}	public void setCust_source(String cust_source) {		this.cust_source = cust_source;	}	public String getCust_industry() {		return cust_industry;	}	public void setCust_industry(String cust_industry) {		this.cust_industry = cust_industry;	}	public String getCust_level() {		return cust_level;	}	public void setCust_level(String cust_level) {		this.cust_level = cust_level;	}	public String getCust_phone() {		return cust_phone;	}	public void setCust_phone(String cust_phone) {		this.cust_phone = cust_phone;	}	public String getCust_mobile() {		return cust_mobile;	}	public void setCust_mobile(String cust_mobile) {		this.cust_mobile = cust_mobile;	}	/**	 * 	 */	public Customer() {		super();		// TODO Auto-generated constructor stub	}	/**	 * @param cust_id	 * @param cust_name	 * @param cust_source	 * @param cust_industry	 * @param cust_level	 * @param cust_phone	 * @param cust_mobile	 */	public Customer(long cust_id, String cust_name, String cust_source, String cust_industry, String cust_level,			String cust_phone, String cust_mobile) {		super();		this.cust_id = cust_id;		this.cust_name = cust_name;		this.cust_source = cust_source;		this.cust_industry = cust_industry;		this.cust_level = cust_level;		this.cust_phone = cust_phone;		this.cust_mobile = cust_mobile;	}	@Override	public String toString() {		return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + ", cust_source=" + cust_source				+ ", cust_industry=" + cust_industry + ", cust_level=" + cust_level + ", cust_phone=" + cust_phone				+ ", cust_mobile=" + cust_mobile + "]";	}				}

(5) xml编写: 将底层数据表和pojo建立关系。

命名规范: 类名.hbm.xml (!!必须满足)
案例: Customer.hbm.xml

(6)创建一个    Hibernate 运行的一个核心的配置文件。   命名: hibernate.cfg.xml    放在src 路径下: (目的方便读取)   	    四个连接数据的参数: 	    配置数据库的方言:  必须的: 	    三个可选操作: 	    打印sql : 	    带有格式打印: 	    是否自动生成ddl语句的。  (7)测试:   a:读取Hibernate的核心配置文件: Configuration config = new Configuration().config(); b:获得一个工厂:SessionFactoey factory =  config.buildSessionFactoey();  c:获得一个session: Session session =  factory.openSession(); d:开启事务:   Transaction tx = session.beginTransaction();              tx.commit();              e: 通过session 对象, 就可以完成CRUD 操作“: 调用session的方法: 即可 f: 关闭session:

三: 细节问题:

工具的提示问题:
配置:

转载地址:http://agmen.baihongyu.com/

你可能感兴趣的文章
Java线程:新特征-线程池
查看>>
interface与abstract class区别
查看>>
axis2创建web service1
查看>>
axis2创建web service2
查看>>
axis2创建web service(三)
查看>>
axis2创建web service(四)
查看>>
Apache Axis2 环境搭配详解
查看>>
Axis2介绍
查看>>
全面接触java集合框架
查看>>
JAVA集合小结
查看>>
Java中的集合
查看>>
SOA、网格计算、云计算与P2P技术
查看>>
Junit4 标注总结
查看>>
Spring事务配置的五种方式
查看>>
关系型数据库性能优化总结
查看>>
IBM MQ 学习笔记
查看>>
MB与MQ简介
查看>>
MQ3
查看>>
MQ 消息列队
查看>>
eclipse的内存设置始终会提示内存溢出
查看>>