[关闭]
@snail-lb 2016-07-20T07:19:09.000000Z 字数 15798 阅读 776

Hibernate

一、hibernate是什么

  1. 一种框架,一种orm框架
    (objext relation mapping)对象关系映射框架。
  2. hibernate处于项目的持久层位置,又叫持久化框架。
  3. hibernate实际上是对jdbc进行轻量级的封装。

二、需求

  1. 切换数据库需要重写编写sql。
  2. 使用jdbc操作数据库语句编写比较麻烦。
  3. 让程序员只关注业务逻辑,不再关心数据库。

三、快速入门案例

使用手动配置hibernate方式开发一个hibernate项目,完成相关操作。

开发流程

  1. 创建一个项目
  2. 画出简单的项目框架图
  3. 引入Hibernate包
  4. 开发Hibernate三种方式

    • 由Domain object --> mapping --> db。 (官方推荐)
    • 由DB开始,用工具生成Mapping的Domain object。(使用较多)
    • 由映射文件开始。

我们使用第二种方式
首先在hibernate数据库下创建student表

  1. create table student(
  2. id int primary key,
  3. name varchar(20) not null,
  4. age varchar(20) not null,
  5. );

5.开发domain对象 和对象关系映射
对象关系映射文件,用于指定domain对象和表的映射关系,该文件的取名有规范,domain对象hbm.xml,一般和domain对象同一包下。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  5. <hibernate-mapping package="com.sun.hibernate.model">
  6. <class name="Student">
  7. <id name="id"></id>
  8. <property name="name"></property>
  9. <property name="age"></property>
  10. </class>
  11. </hibernate-mapping>

6.手动配置hibernate.cfg.xml文件,该文件用于配置连接的数据库类型,diver,用户名,密码....同时管理对象关系映射文件和该文件的名称,这个文件一般放在src目录下。

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <session-factory>
  7. <!-- Database connection settings -->
  8. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  9. <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
  10. <property name="connection.username">root</property>
  11. <property name="connection.password"></property>
  12. <!-- JDBC connection pool (use the built-in) -->
  13. <!-- <property name="connection.pool_size">1</property> -->
  14. <!-- SQL dialect -->
  15. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  16. <!-- Echo all executed SQL to stdout -->
  17. <property name="show_sql">true</property>
  18. <!-- Enable Hibernate's automatic session context management -->
  19. <!--<property name="current_session_context_class">thread</property>-->
  20. <!-- Drop and re-create the database schema on startup -->
  21. <!-- <property name="hbm2ddl.auto">create</property> -->
  22. <!-- Disable the second-level cache -->
  23. <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  24. <mapping resource="com/sun/hibernate/model/Student.hbm.xml"/>
  25. </session-factory>
  26. </hibernate-configuration>

7. 创建对应的student模型

  1. package com.sun.hibernate.model;
  2. public class Student {
  3. private int id;
  4. private String name;
  5. private int age;
  6. public int getId() {
  7. return id;
  8. }
  9. public void setId(int id) {
  10. this.id = id;
  11. }
  12. public String getName() {
  13. return name;
  14. }
  15. public void setName(String name) {
  16. this.name = name;
  17. }
  18. public int getAge() {
  19. return age;
  20. }
  21. public void setAge(int age) {
  22. this.age = age;
  23. }
  24. }

8.测试方法(向数据库中添加一条数据)

  1. package com.sun.hibernate.model;
  2. import org.hibernate.SessionFactory;
  3. import org.hibernate.cfg.Configuration;
  4. import org.hibernate.classic.Session;
  5. public class StudentTest {
  6. public static void main(String[] args){
  7. Student s = new Student();
  8. s.setId(1);
  9. s.setName("s1");
  10. s.setAge(2);
  11. //1.创建Configuration ,该对象用于读取hibernate.cfg.xml,并完成初始化
  12. Configuration cfg = new Configuration();
  13. //2.创建SessionFactory<这是一个会话工厂,是一个重量级对象>
  14. SessionFactory sf = cfg.configure().buildSessionFactory();
  15. //3.创建一个session,相当于jdbc Connection<不是jsp中的那个session>
  16. Session session = sf.openSession();
  17. //4.对hibernate而言,要求程序员在进行增加,删除,修改时必须使用事物提交
  18. session.beginTransaction();
  19. session.save(s); //insert into ... <sql语句被hibernate封装了>
  20. session.getTransaction().commit();
  21. session.close();
  22. sf.close();
  23. }
  24. }

直接运行StudentTest就可以将数据插入到数据库中了。

四、 hibernate缓存原理

详细信息

1.session缓存(一级缓存)

Session内置不能被卸载,Session的缓存是事务范围的缓存(Session对象的生命周期通常对应一个数据库事务或者一个应用事务)。
一级缓存中,持久化类的每个实例都具有唯一的OID。

什么操作会向一级缓存放东西?
save,update,saveOrUpdate,load,get,list,iterate.lock
save案例:

  1. //添加一个学
  2. Student student = new Student();
  3. student.setName("向东");
  4. s.save(student);//放入一级缓存
  5. //马上查询
  6. Student student_2 = (Student)session.get(Student.class,student.getId());
  7. System.out.println(student_2.getName());

什么操作会从一级缓存存取数据。
get/load
get/load 会首先向一级缓存中去取,如没有再有不同的操作(get会立即向数据库发送请求,而load会返回一个代理对象,直到用户真的去使用数据,才会向数据库中发送请求)。
query.list(),query.uniueResult()不会向一级缓存中取数据,但是会向一级缓存中存放数据。

一级缓存一般不需要配置就可以使用,它本身没有保护机制,很有可能造成内存泄漏。所以我们程序员要考虑这个问题。可以使用evict()方法
或者clear()方法清除session中缓存。
(evict()是清除一个对象,clera()是清除所有对象)

session缓存中对象的生命周期,当session关闭后就自动销毁。

2.二级缓存

为什么需要二级缓存?
因为一级缓存有限,而且生命周期很短,所以我们需要二级缓存来弥补这个问题。
1. 需要配合
2. 二级缓存都是交给第三方去处理,常见的有Hashtable,OSCache,EHCache
3. 二级缓存原理
4. 二级缓存对象可能放在内存中夜哭能放在磁盘中。

第二级缓存是可选的,是一个可配置的插件,默认下SessionFactory不会启用这个插件。
Hibernate提供了org.hibernate.cache.CacheProvider接口,它充当缓存插件与Hibernate之间的适配器。

什么样的数据适合存放到第二级缓存中?   
1) 很少被修改的数据   
2) 不是很重要的数据,允许出现偶尔并发的数据   
3) 不会被并发访问的数据   
4) 常量数据   
不适合存放到第二级缓存的数据?   
1) 经常被修改的数据   
2) 绝对不允许出现并发访问的数据,如财务数据,绝对不允许出现并发   
3) 与其他应用共享的数据。

二级缓存配置:(针对hibernate5.2)

  1. <!-- 启用二级缓存 -->
  2. <property name="cache.use_second_level_cache">true</property>
  3. <!--指定是哪一个缓存提供商提供的缓存方法-->
  4. <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
  1. <!--
  2. ~ Hibernate, Relational Persistence for Idiomatic Java
  3. ~
  4. ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  5. ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  6. -->
  7. <ehcache>
  8. <!-- Sets the path to the directory where cache .data files are created.
  9. If the path is a Java System Property it is replaced by
  10. its value in the running VM.
  11. The following properties are translated:
  12. user.home - User's home directory
  13. user.dir - User's current working directory
  14. java.io.tmpdir - Default temp file path -->
  15. <diskStore path="java.io.tmpdir"/>
  16. <!--Default Cache configuration. These will applied to caches programmatically created through
  17. the CacheManager.
  18. The following attributes are required for defaultCache:
  19. maxInMemory - Sets the maximum number of objects that will be created in memory
  20. eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
  21. is never expired.
  22. timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
  23. if the element is not eternal. Idle time is now - last accessed time
  24. timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used
  25. if the element is not eternal. TTL is now - creation time
  26. overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
  27. has reached the maxInMemory limit.
  28. -->
  29. <defaultCache
  30. maxElementsInMemory="10000"
  31. eternal="false"
  32. timeToIdleSeconds="120"
  33. timeToLiveSeconds="120"
  34. overflowToDisk="true"
  35. />
  36. <!--Predefined caches. Add your cache configuration settings here.
  37. If you do not have a configuration for your cache a WARNING will be issued when the
  38. CacheManager starts
  39. The following attributes are required for defaultCache:
  40. name - Sets the name of the cache. This is used to identify the cache. It must be unique.
  41. maxInMemory - Sets the maximum number of objects that will be created in memory
  42. eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element
  43. is never expired.
  44. timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
  45. if the element is not eternal. Idle time is now - last accessed time
  46. timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used
  47. if the element is not eternal. TTL is now - creation time
  48. overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache
  49. has reached the maxInMemory limit.
  50. -->
  51. <!-- Sample cache named sampleCache1
  52. This cache contains a maximum in memory of 10000 elements, and will expire
  53. an element if it is idle for more than 5 minutes and lives for more than
  54. 10 minutes.
  55. If there are more than 10000 elements it will overflow to the
  56. disk cache, which in this configuration will go to wherever java.io.tmp is
  57. defined on your system. On a standard Linux system this will be /tmp"
  58. -->
  59. <cache name="sampleCache1"
  60. maxElementsInMemory="10000"
  61. eternal="false"
  62. timeToIdleSeconds="300"
  63. timeToLiveSeconds="600"
  64. overflowToDisk="true"
  65. />
  66. <!-- Sample cache named sampleCache2
  67. This cache contains 1000 elements. Elements will always be held in memory.
  68. They are not expired. -->
  69. <cache name="sampleCache2"
  70. maxElementsInMemory="1000"
  71. eternal="true"
  72. timeToIdleSeconds="0"
  73. timeToLiveSeconds="0"
  74. overflowToDisk="false"
  75. />
  76. <!-- Place configuration for your caches following -->
  77. </ehcache>
  1. <cache usage="read-only"/>

Hibernate查找对象如何应用缓存?
当Hibernate根据ID访问数据对象的时候,首先从Session一级缓存中查;
查不到,如果配置了二级缓存,那么从二级缓存中查;
如果都查不到,再查询数据库,把结果按照ID放入到缓存删除、更新、增加数据的时候,同时更新缓存。

五、 Query接口

通过Query接口我们可以完成更加复杂的查询任务

###快速入门

  1. /*获取query应用【这里student不是表,而是domain】
  2. where后面的条件可以是一个类的属性名,也可以是表的字段,按照hibernate规定,我们还是应该使用类的属性名*/
  3. Query query = session.createQuery("from Teacher where id = 2");
  4. //通过list方法获取结果,这个list会自动将封装成对应的dommain
  5. //所以我们jdbc进行二次封装的工作没有
  6. List<Teacher> list = query.list();
  7. for(Teacher tea: list){
  8. System.out.println(tea.getName() + " " + tea.getAge());
  9. }

六、 criteria接口简单使用

快速入门

  1. Criteria cri = session.createCriteria(Teacher.class).setMaxResults(4);
  2. List<Teacher> list = cri.list();
  3. for(Teacher tea:list){
  4. System.out.println(tea.getId() + " " + tea.getName());
  5. }

六、HQL

(hibernate query language)

1.需求

在现有的只是基础上,对对象的批量删除,修改,查询还不能很方便的实现。

模拟创建表

2.list

查询所有对象

  1. List<Student> list = session.createQuery("from Student").list();

3.uniqueResult

如果检索一个对象,明确知道最多只有一个,则建议使用该方法。
具体用法:

  1. Student stu = (Student) session.createQuery(" from Student where sid = 20040001").uniqueResult();

4.HQL常见用法

distinct的用法:(用于过滤重复记录)

  1. List<Object[]> list = (List<Object[]>)session.createQuery(" select distinct ssex,sage from Student").list();

between...and的用法

  1. List<Object[]> list = (List<Object[]>)session.createQuery(" select distinct sname,ssex,sage from Student where sage between 22 and 24").list();

in 和 not in的用法

  1. List<Student> list = session.createQuery("from Student where sdept in ('数学系','计算机系')").list();

group 和 having 和 order by
group用法:(查询各个系的学生的平均年龄)

  1. List<Object[]> list = session.createQuery("select avg(sage),sdept from Student group by sdept").list();

having的使用(显示人数大于等于2的系)

  1. List<Object[]> list = session.createQuery("select count(*),sdept from Student group by sdept having count(*) >= 2").list();

(查询各个系女生的人数)

  1. List<Object[]> list = session.createQuery("select count(*),sdept from Student where ssex='M' group by sdept").list();

order by用法(查询所有学生的成绩拼按照成绩高低排序)

  1. List<Object[]> list = session.createQuery("select student.sname,course.cname,grade from Studcourse order by grade DESC").list();

查询计算机系共有多少学生
如果返回一列数据,取出数据是必须用Object,而不是Object[]

  1. List<Object[]> list = session.createQuery("select count(*) from Student where sdept='计算机系'").list();

查询总成绩是多少

  1. List<Object[]> list = session.createQuery("select sum(grade) from Studcourse").list();

查询课程号为1001的课程名称,最高分和最低分

  1. List<Object[]> list = session.createQuery("select course.cname,min(grade),max(grade) from Studcourse where course.cid=1011").list();

查询各科大于80分的学生的名字,科目,分数

  1. List<Object[]> list =session.createQuery("select student.sname,course.cname,grade from Studcourse where grade > 80").list();

计算各科大于80分的的学生数量

  1. List<Object[]> list = session.createQuery("select course.cname,count(*) from Studcourse where grade>80 group by course.cid").list();

5.HQL分页技术

查询所有学生成绩进行高低排序并只分页显示。

  1. //获取页数
  2. int pageCount = Integer.parseInt(session.createQuery("select count(*) from Studcourse").uniqueResult().toString()) /3 +1;
  3. System.out.println("一共有"+pageCount+"页");
  4. //开始查询
  5. for(int i = 0; i < pageCount; i++){
  6. List<Object[]> list = session.createQuery("select student.sname,course.cname,grade from Studcourse order by grade DESC").
  7. setFirstResult(i*3).setMaxResults(3).list();
  8. for(int j = 0; j < list.size(); j ++) {
  9. Object[] obj = list.get(j);
  10. System.out.println(obj[0].toString() + " " + obj[1].toString() + " " + obj[2].toString());
  11. }
  12. System.out.println("*******第"+(i+1)+"页**********");
  13. }

6.参数绑定

好处:
1.可读性高
2.效果好
3.防止sql注入漏洞

一般写法:

  1. List<Student> list = session.createQuery("from Student where sage = 22 and sname = '张三'").list();

参数绑定写法:
如果我们的参数是冒号形式给出的,则可以这样写:

  1. List<Student> list = session.createQuery("from Student where sage=:sage andsname=:sname").setString("sage", "22").setString("sname", "张三").list();

如果我们的参数是问号形式给出的,则可以这样写:

  1. List<Student> list = session.createQuery("from Student where sage=? and sname=?").setString(0, "22").setString(1, "张三").list();

将绑定分开写:

  1. Query query = session.createQuery("from Student where sage=? and sname=?");
  2. query.setInteger(0, 22);
  3. query.setString(1, "张三");
  4. List<Student> list = query.list();

映射文件中得到hql语句

hibernate提供了一种更加灵活的查询方法。
把hql语句配置到对象关系映射文件

  1. <query name="myquerytest">
  2. from Student
  3. </query>

八、hibernate对象的三种关系映射

  1. one-to-one: 身份证<---->人 丈夫<--->妻子
  2. one-to-many: 部门<--->员工
  3. many-to-one:员工<--->部门
  4. many-to-many:学生<--->老师(尽量避免)
    (在实际开发过程中,如果出现了多对多的关系,我们应该尽量装换为两个一对多或者多对一的关系,这样程序好控制,同时不会有冗余)

one-to-many配置文件
(学生<----->选课表 one<--->many)

  1. //student.hbm.xml
  2. <set name="studcourses" inverse="true">
  3. <key>
  4. <column name="sid" />
  5. </key>
  6. <one-to-many class="com.domain.Studcourse" />
  7. </set>
  1. //Studcourse。

九、 对象的三种状态

1. 瞬时状态(transient)

数据库中没有数据与之对应,超过作用域会被JVM垃圾回收器回收,一般是new出来且且与session没有关联的对象。

2.持久状态(persitent)

数据库中有数据与之对应,与当前session有关联,并且相关联的session没有关闭,事物没有提交;持久对象状态发生改变,在事务提交时会影响数据库(hibernate能检测得到)

3.托管状态/游离状态(datached)

数据库中有数据与之对应,但当前没有session与之关联;脱管状态发生改变时,hibernate不能检测到。

  1. Student stu = new Student(); //stu就是瞬时状态
  2. stu.setSname("王宝强");
  3. stu.setSsex("M");
  4. stu.setSdept("表演系");
  5. stu.setSage(32);
  6. stu.setSaddress("河南");
  7. Session session = null;
  8. Transaction ts = null;
  9. try {
  10. session = HibernateUtil.openSession();
  11. ts = session.beginTransaction();
  12. session.save(stu);
  13. //stu既处于session管理下,
  14. //同时stu被保存到数据库中,因此stu此时是持久态
  15. stu.setSname("唐国强");//hibernate能检测到,并且会提交到数据库中去
  16. ts.commit();
  17. session.close();
  18. //这是stu被保存到数据库中,没有处于session的管理之下
  19. //此时stu就是脱管状态(游离态)
  20. } catch (Exception e) {
  21. if(ts != null){
  22. ts.rollback();
  23. }
  24. throw new RuntimeException(e.getMessage());
  25. }finally{
  26. }

六、 其他

1. 什么是pojo类,他有什么要求?
* pojo类和一张表对应
* 一般放在com.XXX.domain下
* pojo需要一个主键属性(用于标示一个pojo对象)
* 除了主键属性,它还应当有其他属性,属性的访问权限为private
* 提供get/set方法
* 它应当有一个无参构造方法(hibernate反射)
* pojo类其实就是一个javaBean(有时也叫Data对象)

2. hibernate核心类和接口
1. configuration类
2. 读取配置文件
3. 管理关系映射文件
4. 加载hibernate的驱动,url,用户
5. 管理hibernate配置信息

3. hibernate.cfg.xml
4. 对象关系映射文件
5. SessionFactory接口(会话工厂)
1. 可以缓存sql语句和数据(称为session级缓存)
2. 是一个重量级的类,因此需要保证一个数据库有一个SessionFactory
6. 通过SessionFactory获取Session的两个方法
1. openSession()是获取一个新的Session
2. getCurrentSession()获取和当前绑定的session,换言之,在同一个线程中,我们获取的session是同一个session。(如果希望使用getCurrentSession需要配置hibernate.cfg.xml)

  1. <property name="current_session_context_class">thread</property>

3.如何选择
如果在同一个线程中,保证使用同一个session,则使用getCurrentSession(),如果在同一个线程中需要使用不同的Session,则使用opentSession()
4. openSession() 和 getCurrentSession()的区别
* 通过getCurrentSession获取的session在事务提交以后会自动关闭,通过openSession获取的session则必须手动关闭,但是我们建议不管什么形式获取的session都进行判断后手动关闭。
* 如果是通过getCurrentSession()获取session进行查询时,也要进行事务提交。

7. 本地事务:针对一个数据库的事物
全局事务:跨数据库的事物(jta)

8. session接口:
主要功能和作用
1. session一个实例代表与数据库的一次操作。(当然一次操作可以使crud组合)
2. session实例是通过SessionFactory获取,用完需要关闭。
3. session实例是线程不同步的(不安全),因此要保证在同一线程中使用,可以用getCurrentSession()
*4.*session可以看做是持久化管理器,它与持久化操作相关的接口。

get() 和load()区别
1. get()方法直接返回实体类,如果找不到数据则返回null。load()会返回一个实体代理对象(当前这个对象可以自动转化为实体对象)。但当代理对象被调用时,如果数据不存在,就会抛出org.hibernate.ObjectNotFoundException异常。
2. load先到缓存(session缓存/二级缓存)中去查,如果没有则返回一个代理对象(不马上到DB中去找),等后面使用这个代理对象操作的时候,才到DB中去查询,这就是我们常说的load在默认情况下支持延迟加载(lazy--->我们可以在配置文件中关闭懒加载功能).

1.懒加载

简述:当我们查询一个对象的时候,在默认情况下返回的只是该对象普通属性,当用户使用哪个对象属性是才会向数据库中发出一次查询,这种现象我们成为懒加载现象
禁用懒加载功能
方法一:(配置文件中进行禁用)

  1. <class name="employee" lazy="false">

配置说明:(员工-部门 one-to-many)
many-to-one的many这一方如果配置了
<class name="employee" lazy="false">
那么hibernate就会在查询学生many方式,把它相关联的对象也进行查询,这里select语句影响不大。
但是如果在one-to-many的one这方,如果配置了
<class name="Department" lazy="false">
那么hibernate有可能会发出多条sql语句,从而降低程序运行效率。

方法二:(显示初始化,Hibernate.initizlize(代理对象))

  1. Hibernate.initlalize(stu.getDept());

方法三:(通过过滤器openSessionview解决)
在过滤器启动的时候启动session,然后等待过滤器中的其他部分执行完毕之后,我们再提交事务,最后再关闭session。(主要原理:配合过滤器扩大session的使用范围,原来只能在mySessionFactiry中使用,使用过滤器配置后在service中也可以使用。)

  1. //过滤器中中
  2. Session s = null;
  3. Transaction ts = null;
  4. try{
  5. s = HibernateUtil.getCurrentSession();
  6. ts = session.beginTransaction();
  7. args2.doFilter(arg0,arg1);//进入程序主体
  8. ts.commit();
  9. }catch (Exception e){
  10. if(ts != null){
  11. ts.rollback();
  12. }
  13. }finally{
  14. if(session != null && session.isOpen()){
  15. session.close();
  16. }
  17. }

方法四:在ssh中可以实现在service层,标注解决懒加载。
3. get先到缓存(session缓存/二级缓存)中去查,如果没有就到DB中去查(即马上发出sql)。总之,如果你确定DB中有这个对象就用load(),不确定就用get()(这样效率高)

2.主键增长策略

  1. increment
    自增,每次增加一, 适用于所有的数据库,但是不要用在多进程,主键类型是数值型。

  2. identity
    自增,每次增加一,适用于identity数据库(mysql,sql,server),主键类型是数值。

  3. sequence

  4. native
    会根据数据库类型,使用identity,sequence,hilo主键类型是数值型。

  5. hilo
    hilo表示服生成器有hibernate按照一种high/low算法(高地位算法)生成标识符。
    6.uuid
    会根据uuid算法生成128-bit的字符串,主键属性不能是数值型,必须是字符串行。
    7.assigned
    用户自己设置主键值,所以主键属性可以是数值,字符串。
  6. 映射复合主键
  7. foreign
    在one-to-one的关系中,有另一张表的主键来决定自己的主键/外键。

针对mysql【主键是int/long/short建议使用increment、assigned 如果主键是字符串建议使用UUID/assigned】

基于主键的one-to-one则使用foreign

3. hibernate不适合的场景

不适合OLAP(On-Line Analytical Processing 联机分析处理)以查询为主的系统,时候OLTP(on-line procession联机事务处理系统)
对于那些关系模型设计不合理的老系统,也不能发挥hibernate的优势。
数据量大,性能要求苛刻的系统,hibernate也很难达到要求,批量操作数据的效率也不高。

4.最佳时间

对于数据量大,性能要求高的系统不太适用使用hibernate
主要用于事物操作比较多的项目,(石油,税务,crm,财务系统)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注