Hibernate HQL與QBC 常用文法
Hibernate中有兩種查詢方法,一種是HQL 全稱:hibernate Query Language,另外種是QBC 全稱:Query By Criteria,HQL優點是與sql相近,可讀性好,功能強大,效率高。但它是在運作時才被解析,以字元形式出現,是以擴充性差。而QBC提供面向對象的接口,編譯時就可被解析,便于排錯調試,擴充性好,允許使用者擴充Criteria接口。但它與SQL差異很大,可讀性差,不支援報表和子表查詢。
Hibernate 常用文法:
HQL | QBC | 含義 |
---|---|---|
= | Restrictions.eq() | 等于equal |
<> | Restrictions.ne() | 不等于not equal |
> | Restrictions.gt() | 大于greater than |
>= | Restrictions.ge() | 大于等于greater than or equal |
< | Restrictions.lt() | 小于less than |
<= | Restrictions.le() | 小于等于less than or equal |
is null | Restrictions.isnull() | 等于空值 |
is not null | Restrictions.isNotNull() | 非空值 |
like | Restrictions.like() | 字元串模式比對 |
not like | Restrictions.not(Restrictions.like()) | 字元串模式比對) |
and | Restrictions.and() | 邏輯與 |
and | Restrictions.conjunction() | 邏輯與 |
or | Restrictions.or() | 邏輯或 |
or | Restrictions.disjunction() | 邏輯或 |
not | Restrictions.not() | 邏輯非 |
in(清單) | Restrictions.in() | 等于清單中的某一個值 |
not in(清單) | Restrictions.not(Restrictions.in()) | 不等于清單中任意一個值 |