gpt4 book ai didi

java - Hibernate `Session` 是否有一个名为 `find()` 的方法,它接受 HQL 字符串?

转载 作者:行者123 更新时间:2023-12-02 10:56:33 25 4
gpt4 key购买 nike

来自数据库系统概念 6ed

To retrieve students, we can use the following code snippet

Session session = getSessionFactory().openSession();
Transaction txn = session.beginTransaction();
List students =
session.find("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();

The above code snippet uses a query in Hibernate’s HQL query language. The HQL query is automatically translated to SQL by Hibernate and executed, and the results are converted into a list of Student objects. The for loop iterates over the objects in this list and prints them out.

我用谷歌搜索,没有发现 Session 有一个名为 find() 的方法,该方法需要一个 HQL 字符串。它已被弃用还是我错过了?我不确定这本书使用哪个 Hibernate 版本。谢谢。

最佳答案

关于java - Hibernate `Session` 是否有一个名为 `find()` 的方法,它接受 HQL 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51690312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com