Hibernate(一)
1 Hibernate简介
1.1 ORM框架
- 对象关系映射(Object Relation Mapping)。
- 是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换。
- Object:对象,Java对象,此处特指JavaBean。
- Relation:关系,二维表,数据库中的表。
- Mapping:映射。
1.2 什么是Hibernate
- Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装。
- 它将POJO和数据库表建立映射关系,是一个全自动的ORM框架。
- POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通的JavaBean。
- Hibernate可以自动生成SQL语句,自动执行,使得Java程序员可以随心所欲的使用面向对象编程思维来操纵数据库。
- Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序中使用,也可以在Servet/JSP的web应用中使用。
1.3 总结Hibernate
- Hibernate是一个数据持久层的ORM框架,它的主要功能就是将对象映射到表中,操作API,只需要将一个对象存储到数据库,不需要写SQL。
- Hibernate提供了对关系型数据库增删改查操作。
1.4 主流的ORM框架
- JPA:Java Persistence API,JPA通过JDK5.0注解或XML描述对象--关系表的映射关系(只有接口规范)。
- Hibernate:最流行的ORM框架,通过对象--关系映射配置,可以完全脱离底层SQL。
- Mybatis:本来是Apache的一个开源项目iBatis,支持普通的SQL查询,存储过程和高级映射的优秀持久层框架。
- Apache DBUtils。
- Spring JDBC Template。
1.5 Hibernate的优点
- Hibernate对JDBC访问数据库的代码做了封装,大大简化了数据访问层繁琐的重复性的代码。
- Hibernate是一个基于JDBC的主流持久化框架,是一个优秀的ORM实现,它很大程度上简化了DAO层编码工作。
- Hibernate使用Java的反射机制。
- Hibernate的性能非常好,因为它是一个轻量级的框架。映射的灵活性很出色。它支持很多关系型数据库,从一对一到多对多的各种复杂关系。
2 Hibernate的简单使用
2.1 Hibernate的使用步骤
- ①在项目中加入hibernate的maven坐标:
<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>5.4.4.Final</version> </dependency>
- ②创建数据库和数据库表。
- ③编写核心配置文件hibernate.cfg.xml,这个文件有连接数据库的配置。
- ④编写映射文件*.hbm.xml,声明对象如何关联数据库表字段。
- ⑤调用Hibernate的API。
2.2 创建数据库表
- sql:
CREATE DATABASE hibernate; USE hibernate; CREATE TABLE USER ( id INT PRIMARY KEY auto_increment, username VARCHAR ( 50 ),`password` VARCHAR ( 50 ) );
2.3 导入数据库的驱动
- MySQL的驱动的maven坐标:
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.48</version> </dependency>
2.4 编写JavaBean
- User.java
package com.sunxiaping.hibernateDemo.domain;public class User {private Integer id;private String username;private String password;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}
View Code
2.5 编写映射文件
- User.hbm.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping><class name="com.sunxiaping.hibernateDemo.domain.User" table="user" schema="hibernate"><id name="id"><column name="id" /><!-- 使用本地生成策略 --><generator class="native"/></id><property name="username"><column name="username"/></property><property name="password"><column name="password"/></property></class> </hibernate-mapping>
View Code
2.6 编写核心配置文件
- hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration><session-factory><!--配置数据库连接参数--><property name="connection.url"><![CDATA[jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf-8&useSSL=false]]></property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.username">root</property><property name="connection.password">123456</property><!--是否显示SQL--><property name="show_sql">true</property><!--是否格式化SQL--><property name="format_sql">true</property><!--是否自动提交事务--><property name="connection.autocommit">true</property><!--配置JavaBean和表的映射关系--><mapping resource="com/sunxiaping/hibernateDemo/domain/User.hbm.xml"/></session-factory> </hibernate-configuration>
View Code
2.7 测试
- 测试
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();User user = new User();user.setUsername("张三");user.setPassword("123456");session.save(user);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3 API详解
3.1 Configuration配置对象
3.1.1 Hibernate的核心配置文件的多种形式
- hibernate.cfg.xml,通常使用xml配置文件,可以配置内容更丰富。
- hibernate.properties,用于配置key/value形式的内容,key不能重复的。配置有很多局限性,一般不用。
3.1.2 Configuration对象
- Configuration对象就是用来加载核心配置文件的。
- new Configuration()构造方法配置加载的是hibernate.properties文件。
- configure()方案分加载的是hibernate.cfg.xml文件。
- 默认情况下,上面两种配置文件都需要放置在classpath环境中。
public Configuration configure() throws HibernateException {return configure( StandardServiceRegistryBuilder.DEFAULT_CFG_RESOURCE_NAME );}
public static final String DEFAULT_CFG_RESOURCE_NAME = "hibernate.cfg.xml";
3.1.3 加载映射文件
- 在hibernate.cfg.xml中配置即可。
<!--配置JavaBean和表的映射关系--><mapping resource="com/sunxiaping/hibernateDemo/domain/User.hbm.xml"/>
- 在代码中配置(不推荐)
//加载hibernate.cfg.xml文件 Configuration configuration = new Configuration().configure(); configuration.addResource("com/sunxiaping/hibernateDemo/domain/User.hbm.xml");
Configuration configuration = new Configuration().configure(); configuration.addClass(User.class);
3.2 SessionFactory工厂
- SessionFactory相当于java web的连接池,用于管理所有的Session。
- 获取SessionFactory的方式:
SessionFactory sessionFactory = configuration.buildSessionFactory();
- SessionFactory还用于缓存配置信息(数据库配置信息、映射文件、预定义HQL等)。
- SessionFactory是线程安全的,多个线程同时访问,不会出现线程并发访问的问题。
3.3 Session会话
- Session会话的获取,SessionFactory工厂提供了两个方法来获取Session。
- ①获取一个全新的Session:
Session session = sessionFactory.openSession();
- ②获取一个和当前线程绑定的Session:
Session session = sessionFactory.getCurrentSession();
<!--如果要使用Session session = sessionFactory.getCurrentSession();必须在hibernate.cfg.xml中配置如下的信息表明Hibernate将支持将创建的Session和本地线程绑定,底层使用的ThreadLocal,在线程之间共享Session。一旦事务提交或回滚,底层将自动关闭Session --> <property name="current_session_context_class">thread</property>
3.4 Transaction
- 手动管理事务:
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = null;try {transaction = session.beginTransaction();User user = new User();user.setUsername("张三");user.setPassword("123456");session.save(user);int num = 10 / 0;//提交事务 transaction.commit();} catch (Exception e) {e.printStackTrace();if (null != transaction) {transaction.rollback();}}//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
- 在实际开发中是不需要手动管理事务的,而是让事务管理交给Spring管理。
- 事务也可以在hibernate.cfg.xml中配置:
<!--是否自动提交事务:针对insert有效,针对delete无效--> <property name="connection.autocommit">true</property>
3.5 Session的API
3.5.1 get()和load()方法的区别
- get()方法:通过主键id查询,如果没有,返回null。立即查询。
- load()方法:通过主键id查询,如果没有,抛出异常。延迟查询。
- 示例:
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();User user1 = session.get(User.class, 1);System.out.println(user1);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3.5.2 update()方法
- update()方法中的对象必须传递主键。
- 示例:
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();User user = new User();user.setUsername("田七");user.setId(1);session.update(user);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3.5.3 delete()方法
- 第一种方式:先获取要删除的对象然后调用delete()方法(推荐)。
- 第二种方式:删除的对象中必须设置主键。
- 示例:
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();User user = session.get(User.class, 1);if(null != user){session.delete(user);}//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3.6 Query查询对象
- HQL:Hibernate Query Language,Hibernate查询语言。是面向对象查询语言,最终底层需要转化为SQL语句。
- SQL:结构化查询语言,直接面向数据库的查询语言。
- 示例:
package com.sunxiaping.hibernateDemo;import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.query.Query; import org.junit.Test;import java.util.List;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();Query query = session.createQuery("FROM com.sunxiaping.hibernateDemo.domain.User where username = ?1 and password = ?2");query.setParameter(1, "李四");query.setParameter(2, "123456");List list = query.list();System.out.println(list);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3.7 Criteria
- QBC:Query By Criteria,Hibernate提供的纯面向对象的查询语言,提供直接使用POJO对象进行操作。
- 不过,貌似现在Hibernate不推荐这种写法了。
- 示例:
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Restrictions; import org.junit.Test;import java.util.List;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();Criteria criteria = session.createCriteria(User.class);criteria.add(Restrictions.eq("username","李四"));List list = criteria.list();System.out.println(list);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
3.8 SQLQuery
- SQLQuery:使用原生的SQL语句进行查询。
- 并不是所有的SQL都能转换为HQL的。
- 示例:
package com.sunxiaping.hibernateDemo;import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.query.NativeQuery; import org.junit.Test;import java.util.List;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();NativeQuery query = session.createSQLQuery(" select * from user");List<Object[]> list = query.list();for (Object[] object : list) {System.out.println(object);}//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
4 配置文件详解
4.1 hibernate.cfg.xml详解
- 示例:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration><session-factory><!--配置数据库连接参数--><property name="connection.url"><![CDATA[jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf-8&useSSL=false]]></property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.username">root</property><property name="connection.password">123456</property><!--是否显示SQL--><property name="show_sql">true</property><!--是否格式化SQL--><property name="format_sql">true</property><!--Hibernate映射和DDL语句的策略create:根据*.hbm.xml文件创建表,每次都会创建新的表,实际开发中不用。update:如果数据库没有表,会创建表,实际开发中经常使用。create-drop:和create类似,但是SessionFactory关闭,会将表删除,实际开发中不用。validate:校验*.hbm.xml文件,如果和数据库的字段不一致的话,就会抛出异常--><property name="hbm2ddl.auto">update</property><!--方言:每一种数据库都有自己的方言,MySQL有MySQL的方式,Oracle有Oracle的方式--><property name="dialect">org.hibernate.dialect.MySQL55Dialect</property><!--是否自动提交事务--><property name="connection.autocommit">true</property><!--如果要使用Session session = sessionFactory.getCurrentSession();必须在hibernate.cfg.xml中配置如下的信息表明Hibernate将支持将创建的Session和本地线程绑定,底层使用的ThreadLocal,在线程之间共享Session。一旦事务提交或回滚,底层将自动关闭Session--><property name="current_session_context_class">thread</property><!--配置JavaBean和表的映射关系--><mapping resource="com/sunxiaping/hibernateDemo/domain/User.hbm.xml"/></session-factory> </hibernate-configuration>
View Code
4.2 *.hbm.xml文件
4.2.1 实体类的编写规则
- 提供一个无参数的public访问修饰符的构造器。
- 提供一个标识属性,映射数据表主键字段,提供ID。
- 所有属性提供public访问修饰符的setter和getter方法。
- 标识属性应该尽量使用基本数据类型的包装类型。
- 不要用final修饰实体。
4.2.2 持久化对象的唯一标识 OID
- Java是通过地址来区分不同的对象。
- 关系型数据库是通过主键来区分不同的记录。
- Hibernate是通过OID来建立内存中的对象和数据库中记录的对应关系(对象的OID和数据库表的主键对应)。
- 为保证OID的唯一性,应该让Hibernate来为OID赋值。
4.2.3 区分自然主键和代理主键
- 主键需要具备:不为null、不能重复并且不能改变。
- 自然主键:在业务中,某个属性符合主键的三个要求。那么该属性可以作为主键列(比如身份证号)。
- 代理主键:在业务中,不存在符合主键条件的要求的属性,那么就需要增加一个没有意义的列,作为主键。
- 在实际开发中,经常使用的是代理主键。
4.2.4 基本数据类型和包装类型
- 基本数据类型和包装类型对应Hibernate的映射类型相同。
- 基本数据类型无法表示null,数字类型默认值为0。
- 包装类型的默认值是null。
4.2.5 Hibernate和对象类型对应
4.2.6 主键生成策略
- 配置在id标签中的generator标签里面:
<id name="id"><column name="id"/><!-- 使用本地生成策略 --><generator class="native"/> </id>
- 其属性值如下:
- ①native:使用的是本地策略,如果是MySQL的话,使用的auto_increment。
- ②identity:MySQL的自动增长。
- ③sequence:Oracle的自动增长。
- ④increment:Hibernate内部的实现,会执行select max(id),然后+1,会有线程并发问题。
- ⑤uuid:保存的时候不用设置id主键,Hibernate会默认提供。
- ⑥assigned:需要手动设置id属性。
4.2.7 动态插入和动态更新
- 在实际开发过程中,我们的POJO对象中难免会有null值的出现,如果不配置动态插入和动态更新的话,那么SQL会将null值也凭凑到SQL中。
- 示例:没有动态插入和动态更新
- User.hbm.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping><class name="com.sunxiaping.hibernateDemo.domain.User" table="user" schema="hibernate"><id name="id"><column name="id"/><!-- 使用本地生成策略 --><generator class="native"/></id><property name="username"><column name="username"/></property><property name="password"><column name="password"/></property></class> </hibernate-mapping>
View Code
- User.java
package com.sunxiaping.hibernateDemo.domain;public class User {private Integer id;private String username;private String password;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String toString() {return "User{" +"id=" + id +", username='" + username + '\'' +", password='" + password + '\'' +'}';} }
View Code
- hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration><session-factory><!--配置数据库连接参数--><property name="connection.url"><![CDATA[jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf-8&useSSL=false]]></property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.username">root</property><property name="connection.password">123456</property><!--是否显示SQL--><property name="show_sql">true</property><!--是否格式化SQL--><property name="format_sql">true</property><!--Hibernate映射和DDL语句的策略create:根据*.hbm.xml文件创建表,每次都会创建新的表,实际开发中不用。update:如果数据库没有表,会创建表,实际开发中经常使用。create-drop:和create类似,但是SessionFactory关闭,会将表删除,实际开发中不用。validate:校验*.hbm.xml文件,如果和数据库的字段不一致的话,就会抛出异常--><property name="hbm2ddl.auto">update</property><!--方言:每一种数据库都有自己的方言,MySQL有MySQL的方式,Oracle有Oracle的方式--><property name="dialect">org.hibernate.dialect.MySQL55Dialect</property><!--是否自动提交事务--><property name="connection.autocommit">true</property><!--如果要使用Session session = sessionFactory.getCurrentSession();必须在hibernate.cfg.xml中配置如下的信息表明Hibernate将支持将创建的Session和本地线程绑定,底层使用的ThreadLocal,在线程之间共享Session。一旦事务提交或回滚,底层将自动关闭Session--><property name="current_session_context_class">thread</property><!--配置JavaBean和表的映射关系--><mapping resource="com/sunxiaping/hibernateDemo/domain/User.hbm.xml"/></session-factory> </hibernate-configuration>
View Code
- 测试
package com.sunxiaping.hibernateDemo;import com.sunxiaping.hibernateDemo.domain.User; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test;public class HibernateTest {@Testpublic void test() {//加载hibernate.cfg.xml文件Configuration configuration = new Configuration().configure();//创建会话创建工厂SessionFactory sessionFactory = configuration.buildSessionFactory();//创建会话Session session = sessionFactory.openSession();//开启事务Transaction transaction = session.beginTransaction();User user = new User();user.setUsername("lisi");session.save(user);//提交事务 transaction.commit();//关闭会话 session.close();//关闭会话工厂 sessionFactory.close();} }
View Code
- 示例:配置了动态插入和动态更新,在class标签上配置
- User.hbm.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping><class name="com.sunxiaping.hibernateDemo.domain.User" table="user" schema="hibernate" dynamic-insert="true" dynamic-update="true"><id name="id"><column name="id"/><!-- 使用本地生成策略 --><generator class="native"/></id><property name="username"><column name="username"/></property><property name="password"><column name="password"/></property></class> </hibernate-mapping>
View Code
转载于:https://www.cnblogs.com/xuweiweiwoaini/p/11465118.html
Hibernate(一)相关推荐
- java面试常见问题之Hibernate总结
1 Hibernate的检索方式 Ø 导航对象图检索(根据已经加载的对象,导航到其他对象.) Ø OID检索(按照对象的OID来检索对象.) Ø HQL检索(使用面向对象的HQL查询语言.) ...
- Spring中启用Hibernate二级缓存步骤
1.在applicationContext.xml配置文件中SessionFactory bean中配置缓存 <!-- 配置会话工厂对象 --> <bean id="se ...
- ssh(Struts+spring+Hibernate)三大框架整合-简述
ssh(Struts+spring+Hibernate)三大框架配合使用来开发项目,是目前javaee最流行的开发方式,必须掌握: 注意: 为了稳健起见,每加入一个框架,我们就需要测试一下,必须通过才 ...
- Hibernate框架第二天
### Hibernate的持久化类 ### ---------- **什么是持久化类** 1. 持久化类:就是一个Java类(咱们编写的JavaBean),这个Java类与表建立了映射关系就可以成为 ...
- Hibernate **关于hibernate4.3版本之后org.hibernate.service.ServiceRegistryBuilder被弃用**
之前一直都是使用hibernate4.2.21的我,有一天突然没有使用本地的jar包而是让IDEA自动下载最新版本的hibernate5.2.2之后,发现有几个经常使用的方法报错了. //创建配置对象 ...
- 使用hibernate与mysql时数据不能插入的原因及解决办法
1.背景 之前从没用过hibernate,因此在网上搜了一下hibernate快速入门方面的信息,最后我按照<Myeclipse Hibernate 快速入门 中文版>(CSDN,百度文库 ...
- IntelliJ IDEA下自动生成Hibernate映射文件以及实体类
转自:https://blog.csdn.net/qq_34197553/article/details/77718925 1.构建项目并添加项目结构配置以及配置初始参数 1.1.如图将基本的架子搭建 ...
- Spring Hibernate JPA 联表查询 复杂查询
(转自:http://www.cnblogs.com/jiangxiaoyaoblog/p/5635152.html) 今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的 ...
- 5 -- Hibernate的基本用法 --2 1 Hibernate 下载和安装
1. 下载Hibernate压缩包 2. 解压:文件结构 ⊙ documentation : 该路径下存放了Hibernate的相关文档,包括Hibernate的参考文档和API文档等. ⊙ lib ...
- Hibernate的一级缓存
Hibernate的一级缓存 什么是缓存:缓存将数据库/硬盘上文件中数据,放入到缓存中(就是内存中一块空间).当再次使用的使用,可以直接从内存中获取 缓存的好处:提升程序运行的效率.缓存技术是Hibe ...
最新文章
- php中的__autoload()函数
- java如何理解继承性_理解 Java 的三大特性之继承
- python图像处理专业博客
- python pip install pipenv失败_pipenv 无法创建依赖情况应该怎么处理?大家有什么好的建议吗?...
- 不相交集合求并的路径压缩
- 201521123058 软工阅读第二次作业
- Swift闭包概念与常见使用场景总结
- jquery is 用于查看选择的元素是否匹配选择器。
- paraview远程模式
- inovance变频器说明书参数设置_汇川(INOVANCE)MD300A变频器说明书.pdf
- matlab 冒泡排序函数,MATLAB实现冒泡排序算法
- et中计算机的快捷键,et文件怎么打开,教您怎么打开et文件
- Excel如何查找两列数据不同项
- 单片机波形发生c语言,51单片机波形发生器程序设计
- 结构化、半结构化和非结构化数据
- CleanMyMac最新4.10.5版本 智能一键扫描清理工具
- ARC120F-Wine Thief(非F2)——序列化环
- 怎么使用关键词获取视频列表 API
- 邮箱客户端程序的实现
- android电话录音没有声音,Android通话录音未录制来电语音(示例代码)