zoukankan      html  css  js  c++  java
  • 面试题:谈谈你对hibernate的理解

    说说这类问题一般要和一个东西比較。说说他们的长处和缺点,hibernate就和JDBC比較呗。你就说说JDBC的优缺点。然后说说hibernate的优缺点,最后对照得出hibernate更好。

    hibernate:

       1、概念:ormapping    对象关系映射

           1、操作数据库的框架

               底层是通过jdbc操作数据库的

           2、用面向对象的方式操作数据库

       2、jdbc的缺点

           1、代码太繁琐了

           2、不是面向对象的数据库操作

           3、资源关闭的代码也非常繁琐,每次都得打开、关闭

           4、没有做到数据缓存

           5、移植性比較差

           长处:

              由于是最低层的操作。所以效率比較高

       3、hibernate

           1、代码比較精简了

           2、是面向对象的数据库操作

           3、仅仅须要关闭一个对象就能够了session

           4、数据缓存  一级缓存  二级缓存  查询缓存

           5、移植性比較好

           缺点:

              1、程序猿不能控制sql语句的生成

                  hibernate中有一个hql

              2、假设一个项目对sql语句的优化要求特别高。不适合用hibernate

              3、假设一张表的数据量特别大。不适合用hibernate

    对于查询数据库的sql优化问题。这里有一个面试题,给你一个学生student表,叫你用各种方式查询出指定的学生信息

    这里有五种方式得出指定学生2,3,4的信息

    --方式一
    select *
    from student
    where id in(2,3,4)
    
    --方式二
    select *
    from student
    where id =2 or id=3 or id=4
    
    --方式三
    select *
    from student
    where id between 2 and 4
    
    --方式四
    select *
    from student
    where id>=2 and id<=4
    
    --方式五
    select *
    from student
    where id=2
    union
    select *
    from student
    where id=3
    union
    select *
    from student
    where id=4


  • 相关阅读:
    Spring Cloud 网关服务 zuul 二
    spring cloud 2.x版本 Gateway动态路由教程
    spring cloud 2.x版本 Sleuth+Zipkin分布式链路追踪
    spring cloud 2.x版本 Gateway熔断、限流教程
    spring cloud 2.x版本 Gateway动态路由教程
    spring cloud 2.x版本 Gateway路由网关教程
    spring cloud 2.x版本 Hystrix Dashboard断路器教程
    spring cloud 2.x版本 Config配置中心教程
    [每天进步一点点]mysql笔记整理(三):索引
    [每天进步一点点]mysql笔记整理(二):事务与锁
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7258223.html
Copyright © 2011-2022 走看看