hibernate简单介绍

一: 框架:
集合框架:
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: 

三: 细节问题:
工具的提示问题:
配置:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方-教育技术博主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值