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

 1 Session session = sessionFactory.openSession();

 2 Transaction tx = session.beginTransaction();

 3 for ( int i=0; i<100000; i++ ) {

 4 Customer customer = new Customer(.....);

 5 session.save(customer);

 6 if ( i % 20 == 0 ) { //20, same as the JDBC batch size

 7 //flush a batch of inserts and release memory:

 8 session.flush();

 9 session.clear();

10 }

11 }

12 tx.commit();

13 session.close();

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

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

具体的就是

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

你可能感兴趣的:(Hibernate)