標籤:content hql 資訊 net -- ssi 物件導向 問題 gravity
說說這類問題一般要和一個東西比較。說說他們的長處和缺點,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 studentwhere id in(2,3,4)--方式二select *from studentwhere id =2 or id=3 or id=4--方式三select *from studentwhere id between 2 and 4--方式四select *from studentwhere id>=2 and id<=4--方式五select *from studentwhere id=2unionselect *from studentwhere id=3unionselect *from studentwhere id=4
面試題:談談你對hibernate的理解