hibernate3学习笔记(二十二)|Query缓存机制 - 编程入门网
_22.model.User;14.
15.public class BusinessService {16.
17. public static void main(String[] args) throws IOException, SQLException {18.19. Configuration config = new Configuration().configure();20. SessionFactory sessionFactory = config.buildSessionFactory(); 21. Session session = sessionFactory.openSession();22.
23.24. String hql = "from com.hb3.pack_22.model.User";25.26. Query query = session.createQuery(hql);27.28.// List<?> list = query.list();
29.// Iterator<?> iterator = list.iterator();
30.// while (iterator.hasNext()) {
31.// User user = (User)iterator.next();
32.// System.out.println(user.getRoom().getAddress());
33.// }
34.// System.out.println("=====================================");
35.// list = query.list();
36.// iterator = list.iterator();
37.// while (iterator.hasNext()) {
38.// User user = (User)iterator.next();
39.// System.out.println(user.getRoom().getAddress());
40.// }
41.//42.// System.out.println("++++++++++++++++++++++++++++++++++++++");
43.44. query = session.createQuery(hql);45. Iterator<?> iterator = query.iterate();46. while (iterator.hasNext()) {47. User user = (User)iterator.next();48. System.out.println(user.getName());49. }50. System.out.println("=====================================");51. iterator = query.iterate();52. while (iterator.hasNext()) {53. User user = (User)iterator.next();54. System.out.println(user.getName());55. }56.57. session.close();58. sessionFactory.close();59. }60.}
hibernate3学习笔记(二十二)|Query缓存机制(5)时间:2011-02-03执行结果:
看见,Iterator中的元素并不是一次性返回的,而是一条一条返回的。当数据量庞大时,特性就会下降。 再看下面的测试代码: 1.package com.hb3.pack_22;2.3.import java.io.IOException;4.import java.sql.SQLException;5.import java.util.Iterator;6.import java.util.List;7. 8.import org.hibernate.Query;9.import org.hibernate.Session;10.import org.hibernate.SessionFactory;11.import org.hibernate.cfg.Configuration;12. 13.import com.hb3.pack_22.model.User;14. 15.public class BusinessService {16. 17. pub |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |