hibernate的對象查詢與sql語句的對應

hibernate的對象查詢與sql語句的對應,第1張

hibernate的對象查詢與sql語句的對應,第2張

1:
select * from order
對應hibernate對象查詢:
list orders = session . create criteria(order . class)。list();
2:
SELECT NAME,idproduct對應的hibernate對象的查詢
:
list products = session . create criteria(product . class)。set projection(
projects . property list()
。add(projections . property(\" name \")
。add(projections . property(\" id \")
)。list();
3:
SELECT O.*,P.* FROM ORDERS O,PRODUCT P其中O . ORDER _ ID = P . ORDER _ ID
對應的hibernate對象查詢:
list orders = session . create criteria(order . class)
。setfetchmode ("products",fetchmode.join)
。list();
4:
SELECT * FROM ORDER _ ID = ' 1092 '的訂單;
對應的hibernate對象查詢:
list orders = session . create criteria(order . class)
。add (restrictions.eq ("orderid"," 1092")
。list();
5:
SELECT O.*,P.* FROM ORDERS O,PRODUCT P WHERE
O . ORDER _ ID = P . ORDER _ ID,P . ID = ' 1111
對應的hibernate對象查詢:
list orders = session . create criteria(order . class)
。setfetchmode ("products",fetchmode.join)
。add (restrictions.eq ("id",)
6:
查詢對應於select count(id)from price total > 2000 group by id
:
List orders = session . create criteria(order . class)
。set projection(projections . projection list()
。add(projections . count(" id")
。add(projections . group property(" id")
)
。list();
考試整理:查詢滙縂:
(1)如何獲取session:
configuration CFG = new configuration()
。addclass(order . class);
session factory SF = CFG . buildsession factory();
//open Session
Session sess = SF . opensession();
(2) HQL方法
string Query =" select o from o"
" order as o join o . products as p"
"其中o . price total >:price lower"
"和o .
Query q = sess . create Query(Query);
q . set double(" price total lower",
double . parse double(lower));
q . set double(" price total upper",
double . parse double(upper))
q . list();
(3)Criteria
List List = sess . create Criteria(order . class)
。add(Restrictions.between(lower,upper)
。list();
Order o =(Order)list . iterator . next();

位律師廻複

生活常識_百科知識_各類知識大全»hibernate的對象查詢與sql語句的對應

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情