hi everyone:
Did anyone seen the Hibernate3 testcase in
Code:
hibernate-3.0.1\test\org\hibernate\test\batch
?
There is some code in it:
Code:
Transaction t = s.beginTransaction();
for ( int i=0; i<N; i++ ) {
DataPoint dp = new DataPoint();
dp.setX( new BigDecimal(i * 0.1d) );
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ) );
s.save(dp);
if ( flushInBatches && i % 20 == 0 ) {
s.flush();
s.clear();
}
}
t.commit();
s.close();
s = openSession();
s.setCacheMode(CacheMode.IGNORE);
t = s.beginTransaction();
int i = 0;
[b][color=red]ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
.scroll(ScrollMode.FORWARD_ONLY);[/color] [/b] while ( sr.next() ) {
DataPoint dp = (DataPoint) sr.get(0);
dp.setDescription("done!");
if ( flushInBatches && ++i % 20 == 0 ) {
s.flush();
s.clear();
}
}
t.commit();
s.close();
Why it use the ScrollableResults ?
why set ScrollMode to "FORWARD_ONLY" ? Could I get better performance by doing this? Thks!