所以我有這個長期配合物SQLQuery對原住民:如何將這種原生SQL查詢轉換爲一個HQL
string hql =
@"SELECT *
FROM
(SELECT a.*, rownum r__
FROM
(select f2.filmid,
f2.realisateurid,
f2.titre,
f2.annesortie,
f2.langue,
f2.duree,
f2.resume,
f2.poster,
f2.qtytotal,
f2.qtydisponible from film f2
where f2.filmid in (
select distinct f.filmid
from film f, filmpays fp, pays p, filmgenre fg, genre g, informationpersonnel director, role r, informationpersonnel actor
where f.filmid = fp.filmid
and fp.paysid = p.paysid
and f.filmid = fg.filmid
and fg.genreid = g.genreid
and f.realisateurid = director.personelid
and f.filmid = r.filmid
and r.personelid = actor.personelid
and f.qtydisponible > 0
and upper(f.titre) LIKE :titre
and f.annesortie >= :anneeLow AND f.annesortie <= :anneeHigh
and upper(g.Nomgenre) LIKE :genre
and upper(f.Langue) LIKE :langue
and upper(p.Nom) LIKE :pays
and upper(director.nom) LIKE :realisateur
and upper(actor.nom) LIKE :acteur)
order by f2.annesortie DESC, f2.titre) a
WHERE rownum < ((:page * 8) +1))
WHERE r__ >= (((:page - 1) *8) +1) ";
/*Begin transaction */
ITransaction tx = s.BeginTransaction();
IQuery query = s.CreateQuery(hql);
query.SetString("titre", "%" + sp.Title.ToUpper() + "%");
query.SetInt32("anneeLow", sp.YearLow);
query.SetInt32("anneeHigh", sp.YearHigh);
query.SetString("pays", "%" + sp.Country.ToUpper() + "%");
query.SetString("langue", "%" + sp.Lang.ToUpper() + "%");
query.SetString("genre", "%" + sp.Genre.ToUpper() + "%");
query.SetString("realisateur", "%" + sp.Director.ToUpper() + "%");
query.SetString("acteur", "%" + sp.Actor.ToUpper() + "%");
query.SetInt32("page", page);
IList<Film> movies = query.List<Film>();
tx.Commit();
return movies;
而且我想在100%HQL的方式來寫類似
東西
IList<Cat> moreCats = sess.CreateQuery(
"from Cat as cat where " +
"cat.Name = 'Fritz' or cat.id = :id1 or cat.id = :id2"
).SetInt64("id1", id1)
.SetInt67("id2", id2)
.List<Cat>();
在諮詢了hql文檔後,我已經理解如何在hql中做一個簡單的小查詢,但是如果我有一個complexe從另一個select中選擇,比如我的查詢,我該如何繼續?
謝謝
我希望我可以upvote你100次。澄清你的時間,非常感謝你 – napi15