Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();

hibernate导入大量数据时,为了避免内存中产生大量对象,在编码时注意什么,如何去除?

这个问题,我如果我没记错的话,hibarnate官方手册中就说明了,也有demo,你可以查查;

具体的就是

http://zhidao.baidu.com/question/2201283544888578828.html?qbl=relate_question_3

05-02 06:21