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()) | 不等於列表中任意一個值 |