36hibernate_fetch_7_set_batch_size
hibernate抓取策略,batch-szie在集合上的应用
public void testFetch1() {
Session session = null;
try {
session = HibernateUtils.getSession();
session.beginTransaction();
List classesList = session.createQuery("select c from Classes c").list();
for (Iterator iter=classesList.iterator(); iter.hasNext();) {
Classes classes = (Classes)iter.next();
System.out.println("classes.name=" + classes.getName());
for (Iterator iter1=classes.getStudents().iterator(); iter1.hasNext();) {
Student student = (Student)iter1.next();
System.out.println("student.name=" + student.getName());
}
}
session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}
}
什么都不配置,发10条:
Hibernate: select classes0_.id as id0_, classes0_.name as name0_ from t_classes classes0_
classes.name=班级0
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级0的学生8
student.name=班级0的学生7
student.name=班级0的学生0
student.name=班级0的学生4
student.name=班级0的学生6
student.name=班级0的学生9
student.name=班级0的学生3
student.name=班级0的学生5
student.name=班级0的学生2
student.name=班级0的学生1
classes.name=班级1
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级1的学生5
student.name=班级1的学生4
student.name=班级1的学生6
student.name=班级1的学生0
student.name=班级1的学生1
student.name=班级1的学生7
student.name=班级1的学生9
student.name=班级1的学生8
student.name=班级1的学生2
student.name=班级1的学生3
classes.name=班级2
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级2的学生0
student.name=班级2的学生3
student.name=班级2的学生4
student.name=班级2的学生2
student.name=班级2的学生8
student.name=班级2的学生6
student.name=班级2的学生5
student.name=班级2的学生1
student.name=班级2的学生9
student.name=班级2的学生7
classes.name=班级3
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级3的学生2
student.name=班级3的学生8
student.name=班级3的学生6
student.name=班级3的学生9
student.name=班级3的学生7
student.name=班级3的学生5
student.name=班级3的学生1
student.name=班级3的学生4
student.name=班级3的学生3
student.name=班级3的学生0
classes.name=班级4
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级4的学生2
student.name=班级4的学生1
student.name=班级4的学生7
student.name=班级4的学生6
student.name=班级4的学生4
student.name=班级4的学生5
student.name=班级4的学生3
student.name=班级4的学生0
student.name=班级4的学生9
student.name=班级4的学生8
classes.name=班级5
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级5的学生3
student.name=班级5的学生0
student.name=班级5的学生8
student.name=班级5的学生4
student.name=班级5的学生2
student.name=班级5的学生1
student.name=班级5的学生9
student.name=班级5的学生7
student.name=班级5的学生6
student.name=班级5的学生5
classes.name=班级6
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级6的学生8
student.name=班级6的学生4
student.name=班级6的学生7
student.name=班级6的学生1
student.name=班级6的学生9
student.name=班级6的学生0
student.name=班级6的学生5
student.name=班级6的学生6
student.name=班级6的学生2
student.name=班级6的学生3
classes.name=班级7
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级7的学生9
student.name=班级7的学生3
student.name=班级7的学生5
student.name=班级7的学生1
student.name=班级7的学生0
student.name=班级7的学生2
student.name=班级7的学生7
student.name=班级7的学生8
student.name=班级7的学生6
student.name=班级7的学生4
classes.name=班级8
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级8的学生6
student.name=班级8的学生9
student.name=班级8的学生7
student.name=班级8的学生2
student.name=班级8的学生0
student.name=班级8的学生3
student.name=班级8的学生8
student.name=班级8的学生5
student.name=班级8的学生1
student.name=班级8的学生4
classes.name=班级9
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级9的学生9
student.name=班级9的学生3
student.name=班级9的学生1
student.name=班级9的学生4
student.name=班级9的学生6
student.name=班级9的学生0
student.name=班级9的学生7
student.name=班级9的学生5
student.name=班级9的学生2
student.name=班级9的学生8
配置batch-size="5",发2条:
batch-size属性,可以批量加载实体类,参见:Classes.hbm.xml
<set name="students" inverse="true" cascade="all" batch-size="5">
Hibernate: select classes0_.id as id0_, classes0_.name as name0_ from t_classes classes0_
classes.name=班级0
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid in (?, ?, ?, ?, ?)
student.name=班级0的学生1
student.name=班级0的学生0
student.name=班级0的学生4
student.name=班级0的学生8
student.name=班级0的学生9
student.name=班级0的学生5
student.name=班级0的学生3
student.name=班级0的学生6
student.name=班级0的学生2
student.name=班级0的学生7
classes.name=班级1
student.name=班级1的学生3
student.name=班级1的学生0
student.name=班级1的学生7
student.name=班级1的学生9
student.name=班级1的学生6
student.name=班级1的学生2
student.name=班级1的学生8
student.name=班级1的学生1
student.name=班级1的学生5
student.name=班级1的学生4
classes.name=班级2
student.name=班级2的学生0
student.name=班级2的学生3
student.name=班级2的学生4
student.name=班级2的学生2
student.name=班级2的学生8
student.name=班级2的学生6
student.name=班级2的学生5
student.name=班级2的学生1
student.name=班级2的学生9
student.name=班级2的学生7
classes.name=班级3
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid in (?, ?, ?, ?, ?)
student.name=班级3的学生7
student.name=班级3的学生5
student.name=班级3的学生4
student.name=班级3的学生6
student.name=班级3的学生0
student.name=班级3的学生2
student.name=班级3的学生3
student.name=班级3的学生9
student.name=班级3的学生1
student.name=班级3的学生8
classes.name=班级4
student.name=班级4的学生6
student.name=班级4的学生9
student.name=班级4的学生8
student.name=班级4的学生4
student.name=班级4的学生3
student.name=班级4的学生2
student.name=班级4的学生5
student.name=班级4的学生0
student.name=班级4的学生7
student.name=班级4的学生1
classes.name=班级5
student.name=班级5的学生4
student.name=班级5的学生7
student.name=班级5的学生5
student.name=班级5的学生8
student.name=班级5的学生1
student.name=班级5的学生6
student.name=班级5的学生9
student.name=班级5的学生2
student.name=班级5的学生0
student.name=班级5的学生3
classes.name=班级6
student.name=班级6的学生1
student.name=班级6的学生8
student.name=班级6的学生4
student.name=班级6的学生2
student.name=班级6的学生5
student.name=班级6的学生7
student.name=班级6的学生3
student.name=班级6的学生0
student.name=班级6的学生6
student.name=班级6的学生9
classes.name=班级7
student.name=班级7的学生8
student.name=班级7的学生7
student.name=班级7的学生6
student.name=班级7的学生0
student.name=班级7的学生1
student.name=班级7的学生3
student.name=班级7的学生9
student.name=班级7的学生4
student.name=班级7的学生2
student.name=班级7的学生5
classes.name=班级8
student.name=班级8的学生6
student.name=班级8的学生4
student.name=班级8的学生1
student.name=班级8的学生5
student.name=班级8的学生9
student.name=班级8的学生3
student.name=班级8的学生0
student.name=班级8的学生8
student.name=班级8的学生7
student.name=班级8的学生2
classes.name=班级9
student.name=班级9的学生7
student.name=班级9的学生2
student.name=班级9的学生0
student.name=班级9的学生3
student.name=班级9的学生1
student.name=班级9的学生9
student.name=班级9的学生4
student.name=班级9的学生8
student.name=班级9的学生6
student.name=班级9的学生5
支持Oracle/sqlServer
<property name="hibernate.jdbc.fetch_size">50</property>
<property name="hibernate.jdbc.batch_size">30</property>
public void testFetch1() {
Session session = null;
try {
session = HibernateUtils.getSession();
session.beginTransaction();
List classesList = session.createQuery("select c from Classes c").list();
for (Iterator iter=classesList.iterator(); iter.hasNext();) {
Classes classes = (Classes)iter.next();
System.out.println("classes.name=" + classes.getName());
for (Iterator iter1=classes.getStudents().iterator(); iter1.hasNext();) {
Student student = (Student)iter1.next();
System.out.println("student.name=" + student.getName());
}
}
session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}finally {
HibernateUtils.closeSession(session);
}
}
什么都不配置,发10条:
Hibernate: select classes0_.id as id0_, classes0_.name as name0_ from t_classes classes0_
classes.name=班级0
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级0的学生8
student.name=班级0的学生7
student.name=班级0的学生0
student.name=班级0的学生4
student.name=班级0的学生6
student.name=班级0的学生9
student.name=班级0的学生3
student.name=班级0的学生5
student.name=班级0的学生2
student.name=班级0的学生1
classes.name=班级1
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级1的学生5
student.name=班级1的学生4
student.name=班级1的学生6
student.name=班级1的学生0
student.name=班级1的学生1
student.name=班级1的学生7
student.name=班级1的学生9
student.name=班级1的学生8
student.name=班级1的学生2
student.name=班级1的学生3
classes.name=班级2
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级2的学生0
student.name=班级2的学生3
student.name=班级2的学生4
student.name=班级2的学生2
student.name=班级2的学生8
student.name=班级2的学生6
student.name=班级2的学生5
student.name=班级2的学生1
student.name=班级2的学生9
student.name=班级2的学生7
classes.name=班级3
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级3的学生2
student.name=班级3的学生8
student.name=班级3的学生6
student.name=班级3的学生9
student.name=班级3的学生7
student.name=班级3的学生5
student.name=班级3的学生1
student.name=班级3的学生4
student.name=班级3的学生3
student.name=班级3的学生0
classes.name=班级4
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级4的学生2
student.name=班级4的学生1
student.name=班级4的学生7
student.name=班级4的学生6
student.name=班级4的学生4
student.name=班级4的学生5
student.name=班级4的学生3
student.name=班级4的学生0
student.name=班级4的学生9
student.name=班级4的学生8
classes.name=班级5
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级5的学生3
student.name=班级5的学生0
student.name=班级5的学生8
student.name=班级5的学生4
student.name=班级5的学生2
student.name=班级5的学生1
student.name=班级5的学生9
student.name=班级5的学生7
student.name=班级5的学生6
student.name=班级5的学生5
classes.name=班级6
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级6的学生8
student.name=班级6的学生4
student.name=班级6的学生7
student.name=班级6的学生1
student.name=班级6的学生9
student.name=班级6的学生0
student.name=班级6的学生5
student.name=班级6的学生6
student.name=班级6的学生2
student.name=班级6的学生3
classes.name=班级7
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级7的学生9
student.name=班级7的学生3
student.name=班级7的学生5
student.name=班级7的学生1
student.name=班级7的学生0
student.name=班级7的学生2
student.name=班级7的学生7
student.name=班级7的学生8
student.name=班级7的学生6
student.name=班级7的学生4
classes.name=班级8
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级8的学生6
student.name=班级8的学生9
student.name=班级8的学生7
student.name=班级8的学生2
student.name=班级8的学生0
student.name=班级8的学生3
student.name=班级8的学生8
student.name=班级8的学生5
student.name=班级8的学生1
student.name=班级8的学生4
classes.name=班级9
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid=?
student.name=班级9的学生9
student.name=班级9的学生3
student.name=班级9的学生1
student.name=班级9的学生4
student.name=班级9的学生6
student.name=班级9的学生0
student.name=班级9的学生7
student.name=班级9的学生5
student.name=班级9的学生2
student.name=班级9的学生8
配置batch-size="5",发2条:
batch-size属性,可以批量加载实体类,参见:Classes.hbm.xml
<set name="students" inverse="true" cascade="all" batch-size="5">
Hibernate: select classes0_.id as id0_, classes0_.name as name0_ from t_classes classes0_
classes.name=班级0
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid in (?, ?, ?, ?, ?)
student.name=班级0的学生1
student.name=班级0的学生0
student.name=班级0的学生4
student.name=班级0的学生8
student.name=班级0的学生9
student.name=班级0的学生5
student.name=班级0的学生3
student.name=班级0的学生6
student.name=班级0的学生2
student.name=班级0的学生7
classes.name=班级1
student.name=班级1的学生3
student.name=班级1的学生0
student.name=班级1的学生7
student.name=班级1的学生9
student.name=班级1的学生6
student.name=班级1的学生2
student.name=班级1的学生8
student.name=班级1的学生1
student.name=班级1的学生5
student.name=班级1的学生4
classes.name=班级2
student.name=班级2的学生0
student.name=班级2的学生3
student.name=班级2的学生4
student.name=班级2的学生2
student.name=班级2的学生8
student.name=班级2的学生6
student.name=班级2的学生5
student.name=班级2的学生1
student.name=班级2的学生9
student.name=班级2的学生7
classes.name=班级3
Hibernate: select students0_.classesid as classesid1_, students0_.id as id1_, students0_.id as id1_0_, students0_.name as name1_0_, students0_.classesid as classesid1_0_ from t_student students0_ where students0_.classesid in (?, ?, ?, ?, ?)
student.name=班级3的学生7
student.name=班级3的学生5
student.name=班级3的学生4
student.name=班级3的学生6
student.name=班级3的学生0
student.name=班级3的学生2
student.name=班级3的学生3
student.name=班级3的学生9
student.name=班级3的学生1
student.name=班级3的学生8
classes.name=班级4
student.name=班级4的学生6
student.name=班级4的学生9
student.name=班级4的学生8
student.name=班级4的学生4
student.name=班级4的学生3
student.name=班级4的学生2
student.name=班级4的学生5
student.name=班级4的学生0
student.name=班级4的学生7
student.name=班级4的学生1
classes.name=班级5
student.name=班级5的学生4
student.name=班级5的学生7
student.name=班级5的学生5
student.name=班级5的学生8
student.name=班级5的学生1
student.name=班级5的学生6
student.name=班级5的学生9
student.name=班级5的学生2
student.name=班级5的学生0
student.name=班级5的学生3
classes.name=班级6
student.name=班级6的学生1
student.name=班级6的学生8
student.name=班级6的学生4
student.name=班级6的学生2
student.name=班级6的学生5
student.name=班级6的学生7
student.name=班级6的学生3
student.name=班级6的学生0
student.name=班级6的学生6
student.name=班级6的学生9
classes.name=班级7
student.name=班级7的学生8
student.name=班级7的学生7
student.name=班级7的学生6
student.name=班级7的学生0
student.name=班级7的学生1
student.name=班级7的学生3
student.name=班级7的学生9
student.name=班级7的学生4
student.name=班级7的学生2
student.name=班级7的学生5
classes.name=班级8
student.name=班级8的学生6
student.name=班级8的学生4
student.name=班级8的学生1
student.name=班级8的学生5
student.name=班级8的学生9
student.name=班级8的学生3
student.name=班级8的学生0
student.name=班级8的学生8
student.name=班级8的学生7
student.name=班级8的学生2
classes.name=班级9
student.name=班级9的学生7
student.name=班级9的学生2
student.name=班级9的学生0
student.name=班级9的学生3
student.name=班级9的学生1
student.name=班级9的学生9
student.name=班级9的学生4
student.name=班级9的学生8
student.name=班级9的学生6
student.name=班级9的学生5
支持Oracle/sqlServer
<property name="hibernate.jdbc.fetch_size">50</property>
<property name="hibernate.jdbc.batch_size">30</property>