來自數(shù)據(jù)庫系統(tǒng)概念 6ed要檢索學(xué)生,我們可以使用以下代碼片段Session session = getSessionFactory().openSession();Transaction txn = session.beginTransaction();List students =session.?nd("from Student as s order by s.ID asc");for ( Iterator iter = students.iterator(); iter.hasNext(); ) {Student stud = (Student) iter.next();.. print out the Student information ..}txn.commit();session.close();上面的代碼片段使用了 Hibernate 的 HQL 查詢語言中的查詢。HQL查詢由Hibernate自動翻譯成SQL并執(zhí)行,結(jié)果轉(zhuǎn)化為Student對象列表。for 循環(huán)遍歷此列表中的對象并將它們打印出來。我用谷歌搜索并沒有找到Session一個(gè)方法find(),它需要一個(gè) HQL 字符串。它已被棄用還是我錯(cuò)過了它?我不確定這本書使用的是什么 Hibernate 版本。謝謝。
添加回答
舉報(bào)
0/150
提交
取消