关于Hibernate的List

SunOne 03-09-11

请问如下两种方法,哪种较好:
1.
Query q = session.createQuery("from Cat as c");
List l = q.list();
for (int i=0; i< l.size(); i++) {
Cat c = (Cat)l.get(i);
int id = c.getId();
String name = c.getName();
System.out.println(id+" "+name);
}

2.
Query q = session.createQuery("select c.id, c.name from Cat as c");
List l = q.list();
Object[] row = new Object[2];
for (int i=0; i< l.size(); i++) {
row = l.get(i);
Integer id = (Integer) row[0];
String name = (String) row[1];
System.out.println(id+" "+name);
}

yehs220
2003-09-11 15:20

2比1快

建议加上jcs,用
Query q = session.createQuery("from Cat as c");
q.iterate();





yangstarfly
2003-09-11 16:47

请问怎么加jcs

bruce
2003-09-11 21:39

在hbm文件中,加入
<jcs-cache usage="read-write"/>

bruce
2003-09-11 21:42



<jcs-cache usage="read-write"/>

3Go 1 2 3 下一页