list 和 iterate
list 和 iterate 不同之处
a) list取所有;
b) iterate 先取ID,等到用到的时候再根据ID来取对象;
c) session 中 list 第二次发出,仍会到数据库查询;
d) iterate 第二次,首先找 session 级缓存。
测试1:
@Test
public void testQueryList(){
Session session = sf.getCurrentSession();
session.beginTransaction(); List<Category> li = (List<Category>)session.createQuery("from Category").list(); for(Category c : li){
System.out.println(c.getId() + "-" + c.getName() );
} List<Category> li2 = (List<Category>)session.createQuery("from Category").list();
for(Category c : li2){
System.out.println(c.getId() + "-" + c.getName() );
} session.getTransaction().commit();
}
测试2:
@Test
public void testQueryIterate(){
Session session = sf.getCurrentSession();
session.beginTransaction(); Iterator<Category> it = (Iterator<Category>)session.createQuery("from Category c where c.id < 4").iterate(); while(it.hasNext()){
Category c = it.next();
System.out.println(c.getId() + "-" + c.getName());
} Iterator<Category> it2 = (Iterator<Category>)session.createQuery("from Category c where c.id < 4").iterate();
while(it2.hasNext()){
Category c = it2.next();
System.out.println(c.getId() + "-" + c.getName());
}
session.getTransaction().commit();
}
执行结果:
list 和 iterate的更多相关文章
- iBatis.net 循环iterate,没有foreach
3.9.4. Iterate Element This tag will iterate over a collection and repeat the body content for each ...
- Iterate Files by Tcltk
Iterate Files by Tcltk eryar@163.com Abstract. Tcl/Tk provide a programming system for developing an ...
- ibatis实现Iterate的使用
<iterate property="" /*可选, 从传入的参数集合中使用属性名去获取值, 这个必须是一个List类型, 否则会出现OutofRangeException, ...
- 使用struts的logic:iterate标签遍历列表时得到显示序号
<logic:notEmpty name="sList" scope="request"> <logic:iterate id="e ...
- Hibernate-list()与iterate()方法的区别
对于list方法而言,实际上Hibernate是通过一条Select SQL获取所有的记录.并将其读出,填入到POJO中返回.而iterate 方法,则是首先通过一条Select SQL 获取所有符合 ...
- Atitit 循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate).
Atitit 循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 1.1. 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称之为循环. ...
- hibernate中get,load,list,iterate的用法及比较
首先,get和load都是查询单个对象,而list和iterate为批量查询 注意以下写法仅针对hibernate3的语法. 使用案例如下: // 1. get和load 的用法 Person p = ...
- 循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate)的区别
表示“重复”这个含义的词有很多, 比如循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称 ...
- struts标签<logic:iterate>的用法
<logic:iterate>主要用来处理在页面上输出集合类,集合一般来说是下列之一: 1. java对象的数组 2. ArrayList.Vector.HashMap等 具体用法请参考s ...
- How to Iterate Map
常用iterate 方法 Map<Integer, String> m = new HashMap<Integer, String>(); for(Map.Entry<I ...
随机推荐
- 洛谷 P3332 BZOJ 3110 [ZJOI2013]K大数查询
题目链接 洛谷 bzoj 题解 整体二分 Code #include<bits/stdc++.h> #define LL long long #define RG register usi ...
- Luogu P1282 多米诺骨牌 DP。。背包?
背包...差不多..QWQ 设f[i]为达到差值为i的状态需要多少次,那就很显然了: 注意区分正负不同的代价的循环方向 技巧:如果不想改负数的话,那可以移动一下数组下标,用一个新的指针指向原来的数组 ...
- Luogu P1272 重建道路 树形DP
刚才瞅了半天自己当初写的,终于瞅出来了...QWQ 设f[i][j]表示以i为根的子树,包含j个节点所需砍掉的最小边数 那么可知f[u][1]=u的度: 方程:f[u][j]=min(f[u][j], ...
- HDU 6357.Hills And Valleys-动态规划(区间翻转l,r找最长非递减子序列)
题意:给一串由n个数字组成的字符串,选择其中一个区间进行翻转,要求翻转后该字符串的最长非降子序列长度最长,输出这个最长非降子序列的长度以及翻转的区间的左右端点 #include<bits/std ...
- HDU - 2276 位运算矩阵快速幂
挺有意思的一道题 要会运用一些常见的位运算操作进行优化 题目的本质就是要求下面的式子 \(dp[i][j+1]=(dp[i-1][j]+dp[i][j]) \mod 2\) (第\(i\)个字符在\( ...
- linux下安装软件的方法(mariadb)
一.方式 1. rpm (不推荐使用) 2. yum 安装(非常方便快捷) 3. 编译安装(需要自定制的时候才使用) 二.技术栈 #闭源收费的技术栈: svn + java + apache(web服 ...
- Python入门笔记——(1)数字与表达式
一.算术运算 整除:// 取余:% 乘方:** (a ** b = pow(a, b)) 十六进制表示:0x...,八进制表示0... round(x [, n]):对x从小数点第n位取四舍五入结果, ...
- Tomcat疑难杂症解决记录
1. startup.bat闪退 cmd中运行startup.bat报错: The JRE_HOME environment variable is not defined correctly Thi ...
- opatch on-line patch and standby-fisrt patch
opatch on-line patch and standby-fisrt patch on-line patch 有缺陷,不建议使用,standby-fisrt patch 可以考虑使用 #### ...
- encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)
myeclipse下启动项目后出现错误:encoding specified in XML prolog (UTF-8) is different from that specified in pag ...